更改搜索栏颜色

Pio*_*cki 5 xml android

我想改变SeekBar颜色,正是我想改变被拖动以改变进度值的点的颜色。我知道我可以通过更改“colorAccent”值来做到这一点,但这不是我要做的。

Abh*_*bhi 9

您所指的点称为 SeekBar Thumb。要更改 Seekbar 拇指的颜色,请在style.xml

通过 XML 更改

<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumbTint="your_color"  //gives your color
android:thumb="@drawable/yourseekthumb"  //gives your drawable
android:theme="@style/SeekBarColor" />
Run Code Online (Sandbox Code Playgroud)

您可以thumbTint使用android:thumb.

此方法适用于 API>16。

通过 Java 代码更改 SeekBar 拇指颜色

SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar);
seekbar.getThumb().setColorFilter(your_color, PorterDuff.Mode.MULTIPLY);
Run Code Online (Sandbox Code Playgroud)

此方法仅适用于 android 5 及更高版本。


Nil*_*hod 5

试试这个只需android:thumbTint="@color/colorPrimary"在您的搜索栏中使用即可。

像这样

<SeekBar
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:max="100"
     android:thumbTint="@color/red"
     android:progress="0" />
Run Code Online (Sandbox Code Playgroud)

你可以像这样改变你的搜索栏的thum

Drawable seekbarThumb = getResources().getDrawable( R.drawable.seekbarThumb );
SeekBar mySeekBar = (SeekBar) findViewById(R.id.mySeekBar );
mySeekBar .setThumb(seekbarThumb );
Run Code Online (Sandbox Code Playgroud)