简体   繁体   中英

Customizing the android seekbar thumb

I want to 1) change the color of the thumb to a color int I have in my code. and 2) make sure there is no whitespace between the progress and the thumb

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:

<?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,而不是乘以渲染颜色。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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