5

Is there a way I can change yellow color in the SeekBar android widget?

enter image description here

Any soln?

Gensheriff
  • 395
  • 1
  • 5
  • 17
  • Check this link it may help you. [Changing default seekbar color](http://stackoverflow.com/questions/5314488/changing-default-seekbar-color) – Yugandhar Babu Dec 22 '11 at 05:47
  • I think this is possible from this list of Links -- 1) [Custom Seekbar](http://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-yellow-to-white) 3) [SeekBar Customizing](http://www.anddev.org/seekbar_progressbar_customizing-t6083.html) – Praveenkumar Dec 22 '11 at 05:44
  • This may help u http://techdroid.kbeanie.com/2010/04/custom-progressbar-for-android.html – NikhilReddy Dec 22 '11 at 05:44

1 Answers1

1

Step 1: Create Your Image Drawables (9-Patch)

Before creating any XML drawables, make sure you create the image drawables (including one 9-patch drawable) needed for the seekbar background, handle, and progress sections. The 9-patch drawables will be put to use by the XML drawables in the steps below.

Create the following drawables and place them in your /res/drawable/ folder:

Step 2: SeekBar Progress Drawable

Now create an XML drawable for the Android seekbar progress (the blue-striped section in the example), call it seekbar_progress_bg.xml, and place it in your /res/drawable/ folder:

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

The above XML first draws a semi-transparent, blue gradient, then layers the semi-transparent stripe image on top of the gradient. The highlighted line of code (line 20) refers to the stripe (semi-transparent) image inside your drawable folder, created in Step 1.

For more information on creating custom shapes via XML, check out the Android drawable resources docs, specifically the bitmap and shape sections.

Step 3: SeekBar Background Drawable

Next create the main seekbar progress drawable; it’ll assign a drawable to the seekbar progress and secondaryProgress actions inside your seekbar. Name your drawable something like seekbar_progress.xml, place it inside your /res/drawable/ folder:

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

The first bit of highlighted code above (line 8) is referring to the seekbar background image (9-patch drawable) created in Step 1 and (line 29) is referring to the drawable you created above in Step 2.

Step 4: Bringing it all together…

At this point, all you need to do is call your seekbar_progress drawable when declaring your seekbar:

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

The two lines of highlighted code are setting the progress and thumb drawables for the SeekBar item. The @drawable/seekbar_progress refers to the XML drawable created in the previous step.

dharmendra
  • 7,835
  • 5
  • 38
  • 71
  • 2
    That looks very painful to change just the background heh. – Daniel Ryan May 28 '12 at 03:27
  • 1
    I love how this is a direct copy from http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/ ... It is useful, but you could have used your own words instead. – agweber Jun 02 '12 at 22:50
  • How would you do this if your SeekBarPreference is all in java? – Steve C. Jul 26 '13 at 02:50