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

Android編程自定義進度條顏色的方法詳解

 更新時間:2017年09月07日 11:55:58   作者:ITzhongzi  
這篇文章主要介紹了Android編程自定義進度條顏色的方法,結(jié)合實例形式分析了Android進度條顏色相關(guān)的屬性設(shè)置操作技巧,需要的朋友可以參考下

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

先看效果圖:

老是提些各種需求問題,我覺得系統(tǒng)默認的顏色挺好的,但是Pk不過,誰叫我們不是需求人員呢,改吧!

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

找到xml后,進去找到:

<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>

這是那個默認轉(zhuǎ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)的,擴展性很性,低耦合,所以我們現(xiàn)在只要改變進度條是怎么樣畫出來的就行了 ,但是負責畫進度條的是 <item name="android:progressDrawable">  所以我們可以找到"drawable下的 progress_horizontal 文件,改變他就可以改變進度條顏色。

<?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)的進度條畫出的布局條件

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

我們只要改變這個色值就能改變他的顏色,主要改變的是<item android:id="@android:id/progress">下的色值就行了。

說了這么多,到底怎么做呢,很簡單:

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

創(chuàng)建一個style 標簽,集成系統(tǒng)默認樣式,然后自定義一個新的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>
 <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"
 style="@style/ProgressBar_Mini"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:progress="50" />

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

  • Android網(wǎng)格視圖GridView的使用

    Android網(wǎng)格視圖GridView的使用

    網(wǎng)格視圖GridView的排列方式與矩陣類似,當屏幕上有很多元素(文字、圖片或其他元素)需要按矩陣格式進行顯示時,就可以使用GridView控件來實現(xiàn)
    2016-01-01
  • Android應(yīng)用中拍照后獲取照片路徑并上傳的實例分享

    Android應(yīng)用中拍照后獲取照片路徑并上傳的實例分享

    這篇文章主要介紹了Android應(yīng)用中拍照后獲取照片路徑并上傳的實例分享,文中使用MultipartEntityBuilder制作了一個簡單的上傳工具,需要的朋友可以參考下
    2016-03-03
  • Android滑動拼圖驗證碼控件使用方法詳解

    Android滑動拼圖驗證碼控件使用方法詳解

    這篇文章主要為大家詳細介紹了Android滑動拼圖驗證碼控件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Kotlin?coroutineContext源碼層深入分析

    Kotlin?coroutineContext源碼層深入分析

    表示一個元素或者是元素集合的接口。它有一個Key(索引)的Element實例集合,每一個Element的實例也是一個CoroutineContext,即集合中每個元素也是集合
    2022-11-11
  • Android開發(fā)教程之ContentProvider數(shù)據(jù)存儲

    Android開發(fā)教程之ContentProvider數(shù)據(jù)存儲

    這篇文章主要介紹了Android開發(fā)教程之ContentProvider數(shù)據(jù)存儲的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • Android使用Retrofit仿微信多張圖片拍照上傳

    Android使用Retrofit仿微信多張圖片拍照上傳

    這篇文章主要介紹了Android使用Retrofit仿微信多張圖片拍照上傳的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Kotlin中使用Dagger2可能遇到的坑解決

    Kotlin中使用Dagger2可能遇到的坑解決

    在Android上創(chuàng)建去耦以及容易測試代碼的幾乎每位遲早都要訴諸Dagger,在Kotlin中設(shè)置Dagger有一些不同,所以下面這篇文章主要給大家介紹了關(guān)于Kotlin中使用Dagger2可能遇到的坑的解決方法,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Android圖片壓縮的實例詳解

    Android圖片壓縮的實例詳解

    這篇文章主要介紹了Android圖片壓縮的實例詳解的相關(guān)資料,android圖片壓縮主要有兩種方式:壓縮圖片分辨率與壓縮圖片質(zhì)量,需要的朋友可以參考下
    2017-08-08
  • Android 布局中的android:onClick的使用方法總結(jié)

    Android 布局中的android:onClick的使用方法總結(jié)

    這篇文章主要介紹了Android 布局中的android:onClick的使用方法總結(jié)的相關(guān)資料,設(shè)置點擊時從上下文中調(diào)用指定的方法,這里提供實例幫助大家理解這部分內(nèi)容,需要的朋友可以參考下
    2017-08-08
  • Android基于名稱、修改時間、大小實現(xiàn)文件夾排序

    Android基于名稱、修改時間、大小實現(xiàn)文件夾排序

    這篇文章主要為大家詳細介紹了Android基于名稱、修改時間、大小實現(xiàn)文件夾排序,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-09-09

最新評論

江华| 玉屏| 新源县| 特克斯县| 陵水| 台前县| 潍坊市| 丰台区| 延吉市| 辽阳县| 青龙| 泾川县| 图木舒克市| 浮山县| 永州市| 安徽省| 临颍县| 浦县| 河北区| 大丰市| 耒阳市| 体育| 台安县| 玉田县| 宁蒗| 尖扎县| 阜阳市| 临海市| 卢龙县| 彭水| 平顶山市| 西充县| 泰安市| 景德镇市| 都江堰市| 麻城市| 育儿| 贺州市| 苍南县| 西宁市| 巴彦县|