背景:
阅读新闻
Android代码控制seekbar的样式
[日期:2012-06-01] 来源:Linux社区 作者:csh159 [字体:]
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);
}
}
更多Android相关信息见Android 专题页面 ?tid=11
相关资讯 Android开发入门
本文评论 查看全部评论 (0)
尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯