zoukankan      html  css  js  c++  java
  • 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);
    }
    }
  • 相关阅读:
    Java学习--list,set,Map接口使用
    Java学习--java中的集合框架、Collection接口、list接口
    Java学习--使用 Math 类操作数据
    Java学习--Calendar 类的应用
    Java学习--使用 Date 和 SimpleDateFormat 类表示时间
    Java学习--Java 中基本类型和字符串之间的转换
    Java学习网址
    Java开发学习--Java 中基本类型和包装类之间的转换
    Java学习--Java 中的包装类
    builtroot make menuconfig流程
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/4662580.html
Copyright © 2011-2022 走看看