Search code examples
androidandroid-layoutandroid-studioandroid-seekbar

custom seekbar progress color fades away


I'm trying to make a custom seekbar which has a ceratin color for showing the progress. I tried it using a layerlist defined in xml. The color of the progress fades away when i run the code.

<SeekBar
    android:id="@+id/load_money_seekbar"
    android:layout_marginTop="@dimen/margin_5dp"
    android:paddingLeft="@dimen/padding_5"
    android:paddingRight="@dimen/padding_5"
    android:paddingTop="@dimen/padding_10"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerHorizontal="true"
    android:indeterminate="false"
    android:splitTrack="false"
    android:thumb="@drawable/load_money_arrow"
    android:max="100"
    android:progressDrawable="@drawable/seekbar_loadmoney">     

seekbar_loadmoney.xml

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape android:shape="line">
            <stroke
                android:width="2dp"
                android:color="#bbbbbb" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <shape android:shape="line">
            <stroke
                android:width="2dp"
                android:color="#bbbbbb" />
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="line">
                <stroke
                    android:width="2dp"
                    android:color="#213D8D" />
            </shape>
        </clip>
    </item>
</layer-list>

Please refer th e screen shot enter image description here


Solution

  • After doing lot of research, i got the answer. I wanted my seekbar's progress to be shown programmaticly and the user cannot change the progress of seekbar. So i did this

    seekbar.setEnabled(false)
    

    This makes the color of the progress in the seekbar to fade away. We can achieve the same thing without fading seekbar's progress color by the following code.

            seekbar.setOnTouchListener(new View.OnTouchListener(){
            @Override
            public boolean onTouch(View v, MotionEvent event) {
    
                return true;
            }
        });