最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程實現(xiàn)自定義進(jìn)度條顏色的方法

 更新時間:2015年11月23日 12:44:36   作者:sengeiou  
這篇文章主要介紹了Android編程實現(xiàn)自定義進(jìn)度條顏色的方法,涉及Android進(jìn)度條的樣式布局及功能實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了Android編程實現(xiàn)自定義進(jìn)度條顏色的方法。分享給大家供大家參考,具體如下:

android 自定義進(jìn)度條顏色

先看圖

基于產(chǎn)品經(jīng)理各種自定義需求,經(jīng)過查閱了解,下面是自己對android自定義進(jìn)度條的學(xué)習(xí)過程!

這個沒法了只能看源碼了,還好下載了源碼, sources\base\core\res\res\  下應(yīng)有盡有,修改進(jìn)度條顏色只能找progress ,因為是改變樣式,首先找styles.xml
找到xml后,進(jìn)去找到

<style name="Widget.ProgressBar"> 
    <item name="android:indeterminateOnly">true</item> 
    <item name="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>
<style name="Widget.ProgressBar"> 
    <item name="android:indeterminateOnly">true</item> 
    <item name="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>

這是默認(rèn)轉(zhuǎn)圈的效果style,但今天我們修改的是水平進(jìn)度條顏色!
所以找到

<style name="Widget.ProgressBar.Horizontal"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> 
    <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> 
    <item name="android:minHeight">20dip</item> 
    <item name="android:maxHeight">20dip</item> 
</style>
<style name="Widget.ProgressBar.Horizontal"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> 
    <item name="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)度條是怎么樣畫出來的就行了 ,但是負(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:startColor="#ff9d9e9d" 
          android:centerColor="#ff5a5d5a" 
          android:centerY="0.75" 
          android:endColor="#ff747674" 
          android:angle="270" 
      /> 
    </shape> 
  </item> 
  <item android:id="@android:id/secondaryProgress"> 
    <clip> 
      <shape> 
        <corners android:radius="5dip" /> 
        <gradient 
            android:startColor="#80ffd300" 
            android:centerColor="#80ffb600" 
            android:centerY="0.75" 
            android:endColor="#a0ffcb00" 
            android:angle="270" 
        /> 
      </shape> 
    </clip> 
  </item> 
  <item android:id="@android:id/progress"> 
    <clip> 
      <shape> 
        <corners android:radius="5dip" /> 
        <gradient 
            android:startColor="#ffffd300" 
            android:centerColor="#ffffb600" 
            android:centerY="0.75" 
            android:endColor="#ffffcb00" 
            android:angle="270" 
        /> 
      </shape> 
    </clip> 
  </item> 
</layer-list> 
<?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:startColor="#ff9d9e9d" 
          android:centerColor="#ff5a5d5a" 
          android:centerY="0.75" 
          android:endColor="#ff747674" 
          android:angle="270" 
      /> 
    </shape> 
  </item> 
  <item android:id="@android:id/secondaryProgress"> 
    <clip> 
      <shape> 
        <corners android:radius="5dip" /> 
        <gradient 
            android:startColor="#80ffd300" 
            android:centerColor="#80ffb600" 
            android:centerY="0.75" 
            android:endColor="#a0ffcb00" 
            android:angle="270" 
        /> 
      </shape> 
    </clip> 
  </item> 
  <item android:id="@android:id/progress"> 
    <clip> 
      <shape> 
        <corners android:radius="5dip" /> 
        <gradient 
            android:startColor="#ffffd300" 
            android:centerColor="#ffffb600" 
            android:centerY="0.75" 
            android:endColor="#ffffcb00" 
            android:angle="270" 
        /> 
      </shape> 
    </clip> 
  </item> 
</layer-list> 

看到?jīng)]有,這是系統(tǒng)的進(jìn)度條畫出的布局條件

android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:endColor="#ff747674"

我們只要改變這個色值就能改變他的顏色,主要改變的是<item android:id="@android:id/progress">下的色值就行了
說了這么多,到底怎么做呢, 很簡單

1. 在我們的項目下新建一個 style.xml 文件

創(chuàng)建一個style 標(biāo)簽,集成系統(tǒng)默認(rèn)樣式,然后自定義一個新的progressDrawable  文件,隨后面在layout 中的progress 中引用這個文件就行

<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>
    <item name="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>
<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"
    style="@style/ProgressBar_Mini"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:progress="50" />

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • Android自定義wheelview隨機(jī)選號效果

    Android自定義wheelview隨機(jī)選號效果

    這篇文章主要介紹了Android自定義wheelview隨機(jī)選號效果,利用wheelview實現(xiàn)滾動隨機(jī)選擇號碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android 讀寫文件方法匯總

    Android 讀寫文件方法匯總

    以下是對Android中讀寫文件的方法進(jìn)行了匯總介紹,需要的朋友可以過來參考下
    2013-07-07
  • Android最基本的異步網(wǎng)絡(luò)請求框架

    Android最基本的異步網(wǎng)絡(luò)請求框架

    這篇文章主要為大家詳細(xì)介紹了Android最基本的異步網(wǎng)絡(luò)請求框架,感興趣的小伙伴們可以參考一下
    2016-04-04
  • Android中menu使用詳解

    Android中menu使用詳解

    本文通過實例代碼給大家分享android中menu的使用,感興趣的朋友一起看看吧
    2017-10-10
  • android實現(xiàn)掃描網(wǎng)頁二維碼進(jìn)行網(wǎng)頁登錄功能

    android實現(xiàn)掃描網(wǎng)頁二維碼進(jìn)行網(wǎng)頁登錄功能

    這篇文章主要介紹了android掃描網(wǎng)頁二維碼進(jìn)行網(wǎng)頁登錄效果,掃描成功之后跳轉(zhuǎn)進(jìn)入主頁,具體實現(xiàn)代碼大家參考下本文
    2017-12-12
  • Android自定義圓角ImageView

    Android自定義圓角ImageView

    這篇文章主要介紹了Android自定義圓角ImageView的相關(guān)資料,需要的朋友可以參考下
    2016-01-01
  • 從源碼分析Android的Glide庫的圖片加載流程及特點

    從源碼分析Android的Glide庫的圖片加載流程及特點

    這篇文章主要介紹了從源碼分析Android的Glide庫的圖片加載流程及特點,Glide庫是Android下一款人氣很高的多媒體資源管理庫,特別是在處理gif加載方面受到眾多開發(fā)者青睞,需要的朋友可以參考下
    2016-04-04
  • Flutter應(yīng)用框架搭建之屏幕適配詳解

    Flutter應(yīng)用框架搭建之屏幕適配詳解

    因移動設(shè)備的多樣性,特別是 Android 的碎片化嚴(yán)重,存在各種各樣的分辨率,而 Flutter 跨平臺開發(fā)又需同時支持 Android 和 iOS ,為盡可能的還原設(shè)計圖效果提升用戶體驗,屏幕適配就勢在必行了。本文將詳細(xì)講解Flutter屏幕適配的方法,需要的可以參考一下
    2022-03-03
  • Android頂部工具欄和底部工具欄的簡單實現(xiàn)代碼

    Android頂部工具欄和底部工具欄的簡單實現(xiàn)代碼

    Android頂部工具欄和底部工具欄的簡單實現(xiàn)代碼,需要的朋友可以參考一下
    2013-05-05
  • Android小知識之圖片的3種壓縮方式小結(jié)

    Android小知識之圖片的3種壓縮方式小結(jié)

    這篇文章主要給大家介紹了關(guān)于Android小知識之圖片的3種壓縮方式的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-10-10

最新評論

舞钢市| 石景山区| 泗水县| 浙江省| 河曲县| 顺义区| 三门峡市| 许昌市| 龙胜| 全椒县| 咸丰县| 达日县| 新乐市| 睢宁县| 岢岚县| 前郭尔| 连江县| 永春县| 阳谷县| 冕宁县| 南川市| 福泉市| 公主岭市| 庆安县| 瓦房店市| 怀来县| 怀柔区| 江口县| 新邵县| 太仆寺旗| 光泽县| 桑日县| 西昌市| 德化县| 宽城| 同心县| 祁东县| 河北省| 乳山市| 加查县| 阜平县|