如何在android中更改SeekBar颜色? (编程)

编程入门 行业动态 更新时间:2024-10-24 08:32:24
本文介绍了如何在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颜色? (编程)

本文发布于:2023-10-08 02:43:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   如何在   android   SeekBar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!