android - 如何在 Android 上为 SeekBar 的拇指着色?

标签 android android-seekbar seekbar-thumb

我使用这个方法来改变 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/

相关文章:

android - 从 rangeseekbar 中删除缩略图文本

android - ConstraintSet 中的 setHorizo​​ntalBias 以及以编程方式创建的 View

java - fragment 中的函数使模拟器崩溃

android - 如何更改 FAB 背景颜色

android - 更流畅的 Android SeekBar

java - 上传图片到android服务器

android - 如何设置用户已选择的搜索栏值

android - Exoplayer 搜索栏不适用于方向键

java - 如何去除 Android SeekBar 中 Thumb 周围的气泡?