SeekBar定制

首先,为mSeekbar.java创建自定义类

public class mSeekbar extends SeekBar{

public seekBar (Context context) {

super(context);

Initialise();

}

public seekBar (Context context, AttributeSet attrs) {

super(context, attrs);

Initialise();

}

public seekBar (Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

Initialise();

}

private void Initialise(){

this.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape));

this.setProgressDrawable(getResources().getDrawable(R.drawable.seek_bar_base));

}

}

然后,将此部分添加到您的xml中

android:id="@+id/seekBar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:thumb="@drawable/red_front"

android:padding="0dp"

android:progress="0"

android:indeterminate="false"

android:secondaryProgress="0"

android:thumbOffset="0dp"/>

使用这些Drawables

seek_bar_base.xml

xmlns:android="http://schemas.android.com/apk/res/android">

android:id="@android:id/background">

android:src="@drawable/gray_back"

android:tileMode="repeat">

android:id="@android:id/progress">

xmlns:android="http://schemas.android.com/apk/res/android" >

xmlns:android="http://schemas.android.com/apk/res/android"

android:src="@drawable/gray_front"

android:tileMode="repeat"/>

shape.xml

xmlns:android="http://schemas.android.com/apk/res/android" >

使用的图像,

gray_back.jpg

gray_front.jpg

red_front.jpg

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐