Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为各个样式标记指定颜色_Android_Android Layout_Android Theme_Android Styles - Fatal编程技术网

Android 为各个样式标记指定颜色

Android 为各个样式标记指定颜色,android,android-layout,android-theme,android-styles,Android,Android Layout,Android Theme,Android Styles,是否可以为单个样式元素而不是在主题标记中指定colorPrimary和colorAccent <style name="MyCustomTabLayout" parent="android:Widget"> <item name="colorPrimaryDark">@color/gray900</item> <item name="colorAccent">@color/gray50</item>

是否可以为单个样式元素而不是在主题标记中指定colorPrimary和colorAccent

<style name="MyCustomTabLayout" parent="android:Widget">        
    <item name="colorPrimaryDark">@color/gray900</item>
    <item name="colorAccent">@color/gray50</item>

    <item name="tabBackground">?attr/colorPrimaryDark</item>
    <item name="tabSelectedTextColor">?android:colorAccent</item>
</style>

<style name="MyCustomTabLayout2" parent="android:Widget">        
    <item name="colorPrimaryDark">@color/gray50</item>
    <item name="colorAccent">@color/gray900</item>

    <item name="tabBackground">?attr/colorPrimaryDark</item>
    <item name="tabSelectedTextColor">?android:colorAccent</item>
</style>

@颜色/灰色900
@颜色/灰色50
?属性/原色暗
?android:colorAccent
@颜色/灰色50
@颜色/灰色900
?属性/原色暗
?android:colorAccent

当我尝试这样做时,会应用默认主题。有没有更好的方法可以做到这一点?

小部件在上下文主题中查找其重音颜色等。如果使用最新的appcompat支持库,您可以定义不同的主题来保存样式,并使用
android:theme
属性将它们应用于不同的布局。看

举一个例子:

res/values/themes.xml

<style name="RedThemeOverlay" parent="android:ThemeOverlay.Material">
    <item name="android:colorEdgeEffect">#FF0000</item>
</style>
<ListView
    ...
    android:theme="RedThemeOverlay" />

#FF0000
res/layout/fragment\u list.xml

<style name="RedThemeOverlay" parent="android:ThemeOverlay.Material">
    <item name="android:colorEdgeEffect">#FF0000</item>
</style>
<ListView
    ...
    android:theme="RedThemeOverlay" />