我使用这个方法来改变 SeekBar 的缩略图颜色:
public static void setThumbColor(final SeekBar sb, @ColorInt final int color) {
final Drawable thumb = sb.getThumb();
thumb.setColorFilter(color, PorterDuff.Mode.SRC_IN);
sb.setThumb(thumb);
}
此代码在 Android 5.0 (Lollipop) 及更新版本上运行良好。但是在 Android 4.2.2 或 4.3.1 上我的方法不起作用,拇指的颜色没有改变。
我应该如何更改旧 Android 版本上的拇指颜色?
最佳答案
在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" />
关于android - 如何在 Android 上为 SeekBar 的拇指着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45316841/