android代码控制seekbar的样式
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. */
@Override
public 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);
}
}



摘自 csh159的专栏

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

android代码控制seekbar的样式

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭