2011-12-22 75 views
5

有沒有一種方法可以改變SeekBar android widget中的黃色?如何更改Android中的seekbar顏色?

enter image description here

任何SOLN?

+0

選中此鏈接可能會對您有所幫助。我想這是可能的從這個鏈接列表 - 1)[自定義搜索欄](HTTP)(http:// http://stackoverflow.com/questions/5314488/changing-default-seekbar-color) – 2011-12-22 05:47:35

+0

://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/)2)[SeekBar Color Change](http://stackoverflow.com/questions/ 3480456/seek-bar-change-path-color-from-yel​​low-to-white)3)[SeekBar Customizing](http://www.anddev.org/seekbar_progressbar_customizing-t6083.html) – Praveenkumar 2011-12-22 05:44:59

+0

這可能有助於你http: //techdroid.kbeanie.com/2010/04/custom-progressbar-for-android。html – 2011-12-22 05:44:30

回答

1

第1步:創建您的圖片可繪製(9補丁)

創建任何XML可繪製之前,請確保您創建所需的搜索條背景圖像繪製資源(包括一個9補丁繪製),處理和進度部分。在下面的步驟中,9個補丁的drawable將被XML drawable使用。

創建以下可繪製並將其放置在你的/ RES /繪製/文件夾:

第2步:搜索欄進展可繪製

現在創建爲Android搜索條進步的XML繪製(藍色條紋部分在該示例中),seekbar_progress_bg.xml調用它,並且把它放在/ RES /抽拉/文件夾:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <clip> 
      <shape> 
       <gradient 
        android:startColor="#FF5e8ea3" 
        android:centerColor="#FF32a0d2" 
        android:centerY="0.1" 
        android:endColor="#FF13729e" 
        android:angle="270" 
       /> 
      </shape> 
     </clip> 
    </item> 
    <item> 
     <clip> 
     <bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
      android:src="@drawable/stripe_bg" 
      android:tileMode="repeat" 
      android:antialias="true" 
      android:dither="false" 
      android:filter="false" 
      android:gravity="left" 
     /> 
     </clip> 
    </item> 
</layer-list> 

上述XML第一繪製半透明,藍色漸變,然後層的半透明條帶在gradi頂部的圖像ENT。突出顯示的代碼行(第20行)是指在第1步中創建的可繪製文件夾內的條紋(半透明)圖像。

有關通過XML創建自定義形狀的更多信息,請查看Android可繪製資源文檔,特別是位圖和形狀部分。

步驟3:搜索欄背景繪製對象

接着創建主搜索條進展可拉伸;它會爲你的seekbar中的seekbar progress和secondaryProgress動作分配一個drawable。命名可繪製類似seekbar_progress.xml,將其放置裏面的/ RES /抽拉/文件夾:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@android:id/background"> 
     <nine-patch 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:src="@drawable/seekbar_background" 
      android:dither="true" 
     /> 
    </item> 
    <item android:id="@android:id/secondaryProgress"> 
     <clip> 
      <shape> 
       <gradient 
        android:startColor="#80028ac8" 
        android:centerColor="#80127fb1" 
        android:centerY="0.75" 
        android:endColor="#a004638f" 
        android:angle="270" 
       /> 
      </shape> 
     </clip> 
    </item> 
    <item 
     android:id="@android:id/progress" 
     android:drawable="@drawable/seekbar_progress_bg" 
    /> 
</layer-list> 

的上面突出顯示的代碼(第8行)的第一個比特被參照搜索條背景圖像(9-補丁抽拉)在步驟1中(第29行)創建指的是可繪製在步驟上面創建2

第4步:把它放在一起......

在這一點上,所有你需要做的就是打電話給你seekbar_progress在聲明您的搜索欄時可繪製:

<SeekBar 
     android:id="@+id/frequency_slider" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:max="20" 
     android:progress="0" 
     android:secondaryProgress="0" 
     android:progressDrawable="@drawable/seekbar_progress" 
     android:thumb="@drawable/seek_thumb" 
/> 

突出顯示的代碼的兩行是爲SeekBar項目設置進度和縮略圖。 @ drawable/seekbar_progress指向在上一步中創建的XML drawable。

+2

這看起來很痛苦,只能改變背景。 – Zammbi 2012-05-28 03:27:32

+1

我喜歡這是如何從http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/直接複製...這是有用的,但你可以用自己的話代替。 – agweber 2012-06-02 22:50:16

+0

如果你的SeekBarPreference全部在java中,你會怎麼做? – 2013-07-26 02:50:40

相關問題