2010-07-06 60 views
11

我在我的應用程序中使用了一個SeekBar,我想定製它一點。我已經想出瞭如何更改拇指和背景的Drawable如何在Android中自定義SeekBar的外觀?

我的問題是如何改變SeekBar的大小?如果我只是改變了SeekBar like this, the查看is only clipped and it only shows the top piece of the SeekBar`的高度:

<SeekBar 
    android:layout_height="10dip" 
    style="@style/seekbar_style" /> 

如何改變Seekbar的總體規模?我希望它比標準SeekBar更薄。

+0

你也可以閱讀本教程。 http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/ – Ali 2012-05-11 04:32:52

回答

13

我不知道Seekbars,但Progressbars可以通過使用自定義樣式(在styles.xml定義),像這樣定製:

<style name="MyCustomProgressStyle"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@drawable/custom_progress_drawable</item> 
    <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> 
    <item name="android:minHeight">10dip</item> 
    <item name="android:maxHeight">10dip</item> 
</style> 

然後你就可以建立一個基於自定義繪製android系統的progress_horizontal.xml(它位於AOSP checkoutframeworks/base/core/res/drawable文件夾中)。這是來自開源項目的an example

23

你有這個進度條的等效搜索條確實:

<style name="Widget.SeekBar"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> 
    <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item> 
    <item name="android:minHeight">20dip</item> 
    <item name="android:maxHeight">20dip</item> 
    <item name="android:thumb">@android:drawable/seek_thumb</item> 
    <item name="android:thumbOffset">8px</item> 
    <item name="android:focusable">true</item> 
    </style> 

所以,你可能要覆蓋這一切,做你的方式,你會爲標題欄做,通過定義你自己的風格。

+0

這對我的作品和演示瞭如何改變「大拇指」的形象(我只是無法弄清楚「thumbOffset」是什麼) – 2011-10-11 08:53:34

+1

@RichardLeMesurier thumbOffset只是拇指和seekbar邊緣之間的一個看不見的「間隙」。你將它設置爲阻止拇指遠離兩側移動。 – Glitch 2011-10-12 16:23:51

+0

如何更改「拇指」圖片 – mohitum 2015-03-19 12:03:05