package com.zte;import android.app.Activity;import android.graphics.Color;import android.graphics.drawable.ClipDrawable;import android.graphics.drawable.Drawable;import android.graphics.drawable.GradientDrawable;import android.graphics.drawable.LayerDrawable;import android.os.Bundle;import android.view.Gravity;import android.widget.LinearLayout;import android.widget.ProgressBar;import android.widget.SeekBar;public class SeekbaActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);SeekBar progressBar=(SeekBar)findViewById(R.id.seekBar1);progressBar.setMax(100);progressBar.setProgress(45);progressBar.setSecondaryProgress(50);progressBar.setThumb(getResources().getDrawable(R.drawable.handleview_layout_seek));LayerDrawable progressDrawable = (LayerDrawable) progressBar.getProgressDrawable();Drawable[] outDrawables = new Drawable[progressDrawable.getNumberOfLayers()];for (int i = 0; i < progressDrawable.getNumberOfLayers(); i++) {switch (progressDrawable.getId(i)) {case android.R.id.background:// 设置进度条背景outDrawables[i] = getResources().getDrawable(R.drawable.handleview_layout_seekbar_bg);break;case android.R.id.secondaryProgress:// 设置二级进度条outDrawables[i] = getResources().getDrawable(R.drawable.handleview_layout_seekbar_bg);break;case android.R.id.progress:// 设置进度条ClipDrawable oidDrawable = (ClipDrawable) progressDrawable.getDrawable(i);Drawable drawable=getResources().getDrawable(R.drawable.handleview_layout_seekbar_fg);ClipDrawable proDrawable = new ClipDrawable(drawable,Gravity.LEFT, ClipDrawable.HORIZONTAL);proDrawable.setLevel(oidDrawable.getLevel());outDrawables[i] = proDrawable;break;default:break;}}progressDrawable = new LayerDrawable(outDrawables);progressBar.setProgressDrawable(progressDrawable);}}