如何在android中更改SeekBar颜色? (编程) [英] how to change SeekBar color in android? (Programmatically)

查看:1983
本文介绍了如何在android中更改SeekBar颜色? (编程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的应用程序制作均衡器,但我不确定如何更改搜索栏的拇指和进度颜色。它默认情况下是粉红色的,并不适合我的应用程序的美学。

I made an equalizer to go with my app but I am not sure how I can change the seekbar's thumb and progress color. It seems to be pink by default and that doesn't fit my app's aesthetics.

 SeekBar seekBar = new SeekBar(this);

        seekBar.setId(i);

        seekBar.setLayoutParams(layoutParams);
        seekBar.setMax(upperEqualizerBandLevel - lowerEqualizerBandLevel);

        seekBar.setProgress(mEqualizer.getBandLevel(equalizerBandIndex));
        //seekBar.setBackgroundColor(Color.DKGRAY);
        //seekBar.setDrawingCacheBackgroundColor(Color.DKGRAY);


推荐答案

更改 Seekbar thumb,在 style.xml中创建一个新样式

To change the color of the Seekbar thumb, create a new style in style.xml

<style name="SeekBarColor"
  parent="Widget.AppCompat.SeekBar"> 
  <item name="colorAccent">@color/your_color</item> 
</style>

最后在布局中:

<SeekBar
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:theme="@style/SeekBarColor" />

要更改 Seekbar 进度颜色,请使用这在Java Class中。

To change the Seekbar progress color, use this in Java Class.

seekBar.getProgressDrawable().setColorFilter("yourcolor", PorterDuff.Mode.MULTIPLY);

这两种方法都适用于API> 16.

Both these will work for API>16.

修改

按Java代码更改SeekBar拇指颜色。

To change SeekBar thumb color by Java code.

 seekBar.getProgressDrawable().setColorFilter(getResources().getCo‌​lor(R.color.your_color‌​), PorterDuff.Mode.SRC_ATOP);

这篇关于如何在android中更改SeekBar颜色? (编程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆