2015-09-20 53 views
0

顏色是否可以指定colorPrimary和colorAccent個人風格elments而不是主題標籤指定的個人風格標籤

<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> 

,當我試圖做的是應用這個默認的主題。有沒有一種方法/更好的方法來做到這一點?

回答

0

小部件在上下文主題上查找自己的口音顏色等。如果您使用最新的appcompat suport庫,則可以定義不同的主題來保存樣式,並使用android:theme屬性將它們應用於不同的版式。見https://chris.banes.me/2014/11/12/theme-vs-style/

引述的例子有:

RES /值/的themes.xml

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

RES /佈局/ fragment_list.xml

<ListView 
    ... 
    android:theme="RedThemeOverlay" />