自定义seekbar
android系统自绘的progressbar,seekbar,别提有多丑,一般开发软件都重绘控件,改变风格,效果:
seekbar:
xml
<SeekBar android:id="@+id/seekbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="5dip" android:paddingRight="5dip" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:progressDrawable="@layout/seekbar_style" style="?android:attr/progressBarStyleHorizontal" android:thumb="@layout/thumb" android:layout_weight="1" />
<?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> <corners android:radius="10dip" /> <gradient android:startColor="#ffffffff" android:centerColor="#ff000000" android:endColor="#ff808A87" android:centerY="0.45" android:angle="270" /> </shape> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="10dip" /> <gradient android:startColor="#ffffffff" android:centerColor="#ffFFFF00" android:endColor="#ffAABD00" android:centerY="0.45" android:angle="270" /> </shape> </clip> </item> </layer-list>
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 按下状态 --> <item android:state_pressed="true" android:drawable="@drawable/thumb_normal" /> <!-- 普通无焦点状态 --> <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/thumb_normal" /> </selector>
seekBar = (SeekBar) controlView.findViewById(R.id.seekbar); seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) { if (fromUser) { //if(!isOnline){ vv.seekTo(progress); //} } } @Override public void onStartTrackingTouch(SeekBar arg0) { myHandler.removeMessages(HIDE_CONTROLER); } @Override public void onStopTrackingTouch(SeekBar seekBar) { myHandler.sendEmptyMessageDelayed(HIDE_CONTROLER, TIME); } });源地址:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=70001