开发者

Customizing seekbar in android

开发者 https://www.devze.com 2023-03-10 15:21 出处:网络
I 开发者_运维知识库want to customize seekbar in android. Can anybody guide me how it can be done? I am new to android.<SeekBar

I 开发者_运维知识库want to customize seekbar in android.

Customizing seekbar in android

Can anybody guide me how it can be done? I am new to android.


<SeekBar
                android:id="@+id/seekBar1"
                android:layout_width="match_parent"
                android:layout_height="34dip"
                android:progressDrawable="@drawable/strip"
                android:thumb="@drawable/icon_small"
                android:layout_weight="3.0" />

You can simply set progressDrawble,thumb and backgroung attribute and you will get all you want.


// ------------ custom seekbar
 LayerDrawable layer = (LayerDrawable) verticalSeekBar_1
 .getProgressDrawable();

 Drawable draw1 = (Drawable) layer
 .findDrawableByLayerId(android.R.id.progress);

 Bitmap bitmap1 = BitmapFactory.decodeResource(getApplicationContext()
 .getResources(), R.drawable.scroll_on);

 draw1 = new ClipDrawable(new BitmapDrawable(bitmap1),
 Gravity.AXIS_PULL_BEFORE, ClipDrawable.HORIZONTAL);

 layer.setDrawableByLayerId(android.R.id.progress, draw1);

 Drawable draw2 = (Drawable) layer
 .findDrawableByLayerId(android.R.id.background);

 Bitmap bitmap2 = BitmapFactory.decodeResource(getApplicationContext()
 .getResources(), R.drawable.scroll_off);

 draw2 = new BitmapDrawable(bitmap2);
 layer.setDrawableByLayerId(android.R.id.background, draw2);

// --------------


XML code

 <SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:progressDrawable="@drawable/seek_bar"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:thumb="@drawable/thumbler_small"
    android:indeterminate="false" />

seek_bar.xml

 <?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+android:id/SecondaryProgress"
        android:drawable="@drawable/first"/>
    <item
        android:id="@+android:id/progress"
        android:drawable="@drawable/second"/>
</layer-list>

first drawable is empty or shown not color full area.

second drawable is fill or color full area.

this link help your more.

0

精彩评论

暂无评论...
验证码 换一张
取 消