import android.os.Bundle;
/**
* Seekbar 自定义
* 颜色
* @author Andy
*
*/
public class TestSeekBar extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
}
}
方法一:
-----------------------
main.xml
<SeekBar android:id="@android:id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="23dip"
android:paddingLeft="25dip"
android:paddingRight="25dip"
android:paddingBottom="4dip"
android:progressDrawable="@drawable/seekbar_style"
android:thumb="@drawable/thumb" />
---------------------------------------
<!-- 拖动按钮 thumb.xml-->
<?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_bt_pressed" />
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/thumb_bt" />
</selector>
----------------------------------------------
<!-- seekbar 图形 seekbar_style.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android ">
<!-- SEEKBAR背景底部的颜色 -->
<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>
方法二:
直接定义图片:
<!-- 自定义图片方式 main.xml-->
<SeekBar
android:id="@+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="20"
android:progress="0"
android:secondaryProgress="0"
android:paddingLeft="32px"
android:paddingRight="32px"
android:progressDrawable="@drawable/seekbar_img"
android:thumb="@drawable/thumb"
/>
-------------------------------------------------------------
<!-- seekbar 图形 seekbar_img.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"
android:drawable="@drawable/seekbar_bg" />
<!--全部能量图 -->
<item
android:id="@+android:id/SecondaryProgress"
android:drawable="@drawable/seekbar_rawbcon" />
<!-- 进和能量图 -->
<item
android:id="@+android:id/progress"
android:drawable="@drawable/progress_cookedbacon" />
</layer-list>
----------------------------------
<!-- 拖动按钮 thumb.xml-->
<?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_bt_pressed" />
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/thumb_bt" />
</selector>
/**
* Seekbar 自定义
* 颜色
* @author Andy
*
*/
public class TestSeekBar extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
}
}
方法一:
-----------------------
main.xml
<SeekBar android:id="@android:id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="23dip"
android:paddingLeft="25dip"
android:paddingRight="25dip"
android:paddingBottom="4dip"
android:progressDrawable="@drawable/seekbar_style"
android:thumb="@drawable/thumb" />
---------------------------------------
<!-- 拖动按钮 thumb.xml-->
<?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_bt_pressed" />
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/thumb_bt" />
</selector>
----------------------------------------------
<!-- seekbar 图形 seekbar_style.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android ">
<!-- SEEKBAR背景底部的颜色 -->
<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>
方法二:
直接定义图片:
<!-- 自定义图片方式 main.xml-->
<SeekBar
android:id="@+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="20"
android:progress="0"
android:secondaryProgress="0"
android:paddingLeft="32px"
android:paddingRight="32px"
android:progressDrawable="@drawable/seekbar_img"
android:thumb="@drawable/thumb"
/>
-------------------------------------------------------------
<!-- seekbar 图形 seekbar_img.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"
android:drawable="@drawable/seekbar_bg" />
<!--全部能量图 -->
<item
android:id="@+android:id/SecondaryProgress"
android:drawable="@drawable/seekbar_rawbcon" />
<!-- 进和能量图 -->
<item
android:id="@+android:id/progress"
android:drawable="@drawable/progress_cookedbacon" />
</layer-list>
----------------------------------
<!-- 拖动按钮 thumb.xml-->
<?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_bt_pressed" />
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/thumb_bt" />
</selector>