Android更改seekbar颜色
我的应用程序中有这个Android更改seekbar颜色,android,android-layout,material-components-android,android-seekbar,android-slider,Android,Android Layout,Material Components Android,Android Seekbar,Android Slider,我的应用程序中有这个SeekBar: <SeekBar android:id="@+id/volume_seek_bar" android:layout_width="match_parent" android:layout_height="40dp" android:theme="@style/Volume_Seekbar" /> 这
SeekBar
:
<SeekBar
android:id="@+id/volume_seek_bar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:theme="@style/Volume_Seekbar" />
这是样式文件:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/toolbar_background</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="ProgressBarStyle">
<item name="colorAccent">@color/colorPrimary</item>
</style>
<style name="Volume_Seekbar">
<item name="colorPrimary">@color/app_blue</item>
<item name="colorPrimaryDark">@color/toolbar_background</item>
<item name="colorAccent">@color/app_blue</item>
</style>
@颜色/原色
@颜色/背景
@颜色/颜色重音
@颜色/原色
@颜色/蓝色
@颜色/背景
@颜色/蓝色
我想使用样式更改
SeekBar
的颜色,但它一直从AppTheme
样式中获取颜色定义。知道问题出在哪里吗?使用查看kbar
您可以使用:
<SeekBar
android:theme="@style/MySeekBar"
/>
可以使用以下方法替代默认颜色:
<style name="slider_red">
<item name="colorPrimary">#......</item>
</style>
#......
注意:
滑块
要求材料组件的版本为1.2.0
。您在哪台设备上测试了API级别?@Raj使用Android 9(三星8),API级别为-28
<com.google.android.material.slider.Slider
android:valueFrom="0"
android:valueTo="300"
android:value="200"
android:theme="@style/slider_red"
/>
<style name="slider_red">
<item name="colorPrimary">#......</item>
</style>