如何对API 21以上的所有SeekBar应用样式?

我需要将styles.xml中的样式应用于xml布局中的所有SeekBar视图,因此我尝试了以下方法:

<style name="Apptheme" parent="Theme.AppCompat.Light.NoactionBar">
    <item name="seekBarStyle">@style/SeekBar</item>
</style>

<style name="SeekBar" parent="@style/Widget.AppCompat.SeekBar">
    <item name="coloraccent">@color/button_color</item> <!-- below api 21 it's necessary this line and to add this style with android:theme in the layout xml file -->

    <item name="android:progressBackgroundTint">@color/button_color</item>
    <item name="android:thumbTint">@color/button_color</item>
    <item name="android:thumbTintMode">src_in</item>
    <item name="android:progressTint">@color/button_color</item>
</style>

问题在于它仅在api 21以上的设备中起作用。例如,在具有API 19 kitkat的设备中不起作用。

使其生效的唯一方法是在所有xml布局的android:theme="@style/SeekBar"中的每个SeekBar中伪装此行,但这不是正确的方法。

如何解决这个问题?

hzh600606 回答:如何对API 21以上的所有SeekBar应用样式?

AFAIK Material主题属性(例如android:colorAccent,android:colorPrimary or android:colorPrimaryDark等)旨在与Android 21配合使用,如果您想使用21之前的API级别的属性, 您添加<item name=”colorPrimary”>@color/my_awesome_color</item>values/themes.xml中,在添加AppCompact依赖关系之后,在您的build.gradle中,

dependencies {
    compile "com.android.support:appcompat-v7:21.0.+"
}

您可以在this博客文章中进一步了解

本文链接:https://www.f2er.com/3061701.html

大家都在问