简体   繁体   English

自定义android seekbar thumb

[英]Customizing the android seekbar thumb

I want to 1) change the color of the thumb to a color int I have in my code. 我想1)将拇指的颜色更改为代码中的int颜色。 and 2) make sure there is no whitespace between the progress and the thumb 和2)确保进度和拇指之间没有空格

Drawable thumb = getResources().getDrawable(R.drawable.thumb, getContext().getTheme());
// seekbarColorStr can be #0011FF, etc
thumb.setColorFilter(Color.parseColor(seekbarColorStr), PorterDuff.Mode.MULTIPLY);
seekBar.setThumb(thumb);

My thumb.xml: 我的thumb.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="oval">

<size
    android:height="20dp"
    android:width="20dp" />

</shape>

I got the idea for changing the color in How to change colour of the thumb in seekbar? 我在如何更改搜索栏中的拇指颜色中有了改变颜色的想法

The thumb renders black, and since it is circular while the progress is rectangular, there is whitespace between the two. 拇指呈黑色,并且进度为矩形时呈圆形,因此两者之间有空白。

正确的PorterDuff模式是SRC_IN,而不是乘以渲染颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM