Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize the look of a SeekBar in Android?

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 for the background.

My question is how to change the size of the SeekBar? If I just change the height of the SeekBar like this, theViewis only clipped and it only shows the top piece of theSeekBar`:

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

How do I change the overall size of the Seekbar? I want it to be much thinner then the standard SeekBar.

like image 903
Janusz Avatar asked Jul 06 '10 14:07

Janusz


People also ask

How do I customize SeekBar?

Now go to the activity_main. xml create a layout and inside the layout add a SeekBar. Specify the height width of SeekBar and the max progress that you want to use set progress to 0. This will create a customized Seekbar inside activity_main.

How do I change the SeekBar thumb on Android?

Just add android:thumbTint="@color/yourColor" in your seekbar.

How do I change the color of SeekBar?

If you are using default SeekBar provided by android Sdk then their is a simple way to change the color of that . just go to color. xml inside /res/values/colors. xml and change the colorAccent.


2 Answers

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.

like image 125
Sephy Avatar answered Feb 04 '23 20:02

Sephy


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.

like image 45
Yoni Samlan Avatar answered Feb 04 '23 20:02

Yoni Samlan