今天就跟大家聊聊有關(guān)Android中怎么自定義進(jìn)度條顏色,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
styles.xml
找到xml后,進(jìn)去找到:
<style name="Widget.ProgressBar"> <item name="android:indeterminateOnly">true</item> <itemname="android:indeterminateDrawable">@android:drawable/progress_medium_white</item> <item name="android:indeterminateBehavior">repeat</item> <item name="android:indeterminateDuration">3500</item> <item name="android:minWidth">48dip</item> <item name="android:maxWidth">48dip</item> <item name="android:minHeight">48dip</item> <item name="android:maxHeight">48dip</item> </style>
這是那個(gè)默認(rèn)轉(zhuǎn)圈的,但今天我們不修改這個(gè),我們是要改變水平進(jìn)度條顏色,所以找到:
<style name="Widget.ProgressBar.Horizontal"> <item name="android:indeterminateOnly">false</item> <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> <itemname="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> <item name="android:minHeight">20dip</item> <item name="android:maxHeight">20dip</item> </style>
你看系統(tǒng)一步一步關(guān)聯(lián)的,擴(kuò)展性很性,低耦合,所以我們現(xiàn)在只要改變進(jìn)度條是怎么樣畫出來(lái)的就行了 ,但是負(fù)責(zé)畫進(jìn)度條的是 <item name="android:progressDrawable"> 所以我們可以找到"drawable下的 progress_horizontal 文件,改變他就可以改變進(jìn)度條顏色。
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2008 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#ff5a5d5a" android:centerY="0.75" android:endColor="#ff747674" android:startColor="#ff9d9e9d" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#80ffb600" android:centerY="0.75" android:endColor="#a0ffcb00" android:startColor="#80ffd300" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#ffffb600" android:centerY="0.75" android:endColor="#ffffcb00" android:startColor="#ffffd300" /> </shape> </clip> </item> </layer-list>
看到?jīng)]有,這是系統(tǒng)的進(jìn)度條畫出的布局條件
android:startColor="#80ffd300" android:centerColor="#80ffb600" android:endColor="#ff747674"
我們只要改變這個(gè)色值就能改變他的顏色,主要改變的是<item android:id="@android:id/progress">下的色值就行了。
說(shuō)了這么多,到底怎么做呢,很簡(jiǎn)單:
在我們的項(xiàng)目下新建一個(gè) style.xml 文件
創(chuàng)建一個(gè)style 標(biāo)簽,集成系統(tǒng)默認(rèn)樣式,然后自定義一個(gè)新的progressDrawable 文件,隨后面在layout 中的progress 中引用這個(gè)文件就行。
<style name="ProgressBar_Mini" parent="@android:style/Widget.ProgressBar.Horizontal"> <item name="android:maxHeight">50dip</item> <item name="android:minHeight">8dip</item> <item name="android:indeterminateOnly">false</item> <itemname="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> <item name="android:progressDrawable">@drawable/progressbar_mini</item> </style>
下面是我的 progressbar_mini 文件,改變了下android:endColor="#F5F5F5"
android:startColor="#BEBEBE"
的色值
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerY="0.75" android:endColor="#F5F5F5" android:startColor="#BEBEBE" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="0dip" /> <gradient android:angle="270" android:centerY="0.75" android:endColor="#165CBC" android:startColor="#85B0E9" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerY="0.75" android:endColor="#165CBC" android:startColor="#85B0E9" /> </shape> </clip> </item> </layer-list>
最后引用其就可以了。
<ProgressBar android:id="@+id/progress" android:layout_width="fill_parent" android:layout_height="wrap_content" android:progress="50" />
看完上述內(nèi)容,你們對(duì)Android中怎么自定義進(jìn)度條顏色有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
本文標(biāo)題:Android中怎么自定義進(jìn)度條顏色-創(chuàng)新互聯(lián)
文章源于:http://jinyejixie.com/article36/dphopg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、域名注冊(cè)、網(wǎng)站策劃、關(guān)鍵詞優(yōu)化、定制網(wǎng)站、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容