How to customize the look of a SeekBar in Android?

后端 未结 2 1625
臣服心动
臣服心动 2020-12-28 09:47

I use a SeekBar in my application and I would like to customize it a little bit. I already figured out how to change the Drawable for the thumb and

相关标签:
2条回答
  • 2020-12-28 09:51

    I'm not sure about Seekbars, but Progressbars can be customized by using a custom style (defined in your styles.xml) like so:

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

    Then you can set up a custom drawable based on the android system's progress_horizontal.xml (it's in the frameworks/base/core/res/drawable folder of an AOSP checkout). Here's an example from an open-source project.

    0 讨论(0)
  • 2020-12-28 10:04

    You have the equivalent of this of the Progress Bar for the seekbar indeed :

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

    So you might want to override all this and do it your way, as you would do it for the title bar, by defining your own style.

    0 讨论(0)
提交回复
热议问题