2012-07-09 64 views
5

請幫助爲SeekBar Thumb定義自己的XML drawable。 在這個XML drawable中,我想定義state_selectedstate_pressed的自定義形狀。Android在XML中繪製自己的seekbar thumb

據我瞭解,在XML搜索欄定義,我們必須把android:thumb="@drawable/listview_bg_selector"其中listview_bg_selector樣子:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_selected="false" 
     android:state_pressed="false" 
     android:drawable="@drawable/seekbar_thumb_default" /> 
    <item android:state_pressed="true" 
     android:drawable="@drawable/seekbar_thumb_clicked" 
     /> 
    <item android:state_selected="true" 
     android:state_pressed="false" 
     android:drawable="@drawable/seekbar_thumb_selected" 
     /> 
</selector> 

但下一步做什麼,我在這裏的代碼試圖從可繪製與形狀,但沒有正常工作,我只看到默認的SeekBar。 這個問題有沒有例子?

回答

3

對於未來的求職者,我使用holo-colors.com來創建我自己定製的SeekBar,這讓我非常滿意。

他們還提供函數來創建其他Android元素,如SpinnerSwitch

+0

謝謝,這是一個好主意!此外,我發現它可以作爲IntelliJ和Android Studio的插件https://github.com/jeromevdl/android-holo-colors-idea-plugin – Sergii 2015-01-19 18:15:42

+0

我不知道,謝謝你的提示! @Sergii – Marcus 2015-01-19 18:33:49

4

您可以在此link你真正想要的發現,但它是一個法國網站,你可以專注於源代碼,您可以下載從here

+0

這就是它!非常感謝! – Sergii 2012-07-09 16:44:53

3

這樣的事情解決了這個問題對我來說。

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/seek_thumb_pic"> 
     <shape android:shape="rectangle" /> 
    </item> 

</selector> 

另一種方式可能是在代碼中設置邊界,但我不確定這一點。