关闭

android代码控制seekbar的样式

标签: Android代码控制seekBar样式
328人阅读 评论(0) 收藏 举报
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的专栏

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:13167次
    • 积分:262
    • 等级:
    • 排名:千里之外
    • 原创:12篇
    • 转载:3篇
    • 译文:0篇
    • 评论:4条
    Android大神
    最新评论