SeekBar是ProgressBar的擴充,在其基礎上增加了一個可拖動的thumb(註:就是那個可拖動的表徵圖)。使用者可以觸摸thumb並向左或向右拖動,再或者可以使用方向鍵都可以設定當前的進度等級。
布局檔案:
<SeekBar android:id="@+id/seekbar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="10dp" android:maxHeight="8dp" android:minHeight="8dp" android:progressDrawable="@drawable/seekbar_style" android:thumb="@android:drawable/ic_notification_overlay" android:thumbOffset="0dp" /><TextView android:id="@+id/progress" android:layout_width="fill_parent" android:layout_height="wrap_content" />seekbar的樣式檔案:seekbar_style.xml<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background"><shape > <corners android:radius="10dip" /> <gradient android:angle="270" android:centerColor="#F5F5F5" android:centerY="0.45" android:endColor="#F5F5F5" android:startColor="#F5F5F5" /> </shape> </item> <item android:id="@android:id/progress"><clip > <shape > <corners android:radius="10dip" /> <gradient android:angle="270" android:centerColor="#FF75BC32" android:centerY="0.45" android:endColor="#FF75BC32" android:startColor="#FF75BC32" /> </shape> </clip> </item></layer-list>說明:如果想要改變進度條下面的那個白色的背景槽的顏色,在第一個item裡面進行設定,可以通過設定@null 或者#00000000來把進度槽隱藏掉,如果想要改變進度條的顏色,在第二個種修改成自己需要的顏色即可activity類:public class SeekbarActivity extends Activity implements SeekBar.OnSeekBarChangeListener{private SeekBar mSeekBar;private TextView progressNum; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mSeekBar=(SeekBar) findViewById(R.id.seekbar); progressNum=(TextView) findViewById(R.id.progress); }@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubprogressNum.setText(String.valueOf(progress + 1));}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}}更複雜的邏輯,需要自己根據自己的業務區實現