2016-12-15 24 views
0

請檢查選項1和選項2,在values-v21樣式中定義平臺特定樣式屬性(如android:colorPrimary)有什麼優勢。使用AppCompact時需要哪些特定於版本的樣式項?

值/ styles.xml

<resources> 
    <!-- Base application theme. --> 
    <style name="AppTheme" parent="CommonTheme"> 

    </style> 

    <style name="CommonTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 
</resources> 

選項1:值-V21/styles.xml - 使用AppCompact所有版本的繼承。

<resources> 
    <!-- Base application theme. --> 
    <style name="AppTheme" parent="CommonTheme"> 
     <!-- All customization of the theme for this version --> 
     <item name="android:windowTranslucentStatus">true</item> 
    </style> 
</resources> 

選項2:值-V21/styles.xml - 寫作平臺特定的風格一起繼承屬性。

<resources> 
    <!-- Base application theme. --> 
    <style name="AppTheme" parent="CommonTheme"> 
     <item name="android:colorPrimary">@color/colorPrimary</item> 
     <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="android:colorAccent">@color/colorAccent</item> 
     <item name="android:windowTranslucentStatus">true</item> 
    </style> 
</resources> 

我看到兩個選項在不同的地方,哪個更好?我們在選項2中有什麼優勢嗎?

回答

2

選項2是作爲程序兼容性自身拷貝完全不必要在如見於其values-v21 theme顏色:

<!-- Copy our color theme attributes to the framework --> 
<item name="android:colorPrimary">?attr/colorPrimary</item> 
<item name="android:colorPrimaryDark">?attr/colorPrimaryDark</item> 
<item name="android:colorAccent">?attr/colorAccent</item> 
<item name="android:colorControlNormal">?attr/colorControlNormal</item> 
<item name="android:colorControlActivated">?attr/colorControlActivated</item> 
<item name="android:colorControlHighlight">?attr/colorControlHighlight</item> 
<item name="android:colorButtonNormal">?attr/colorButtonNormal</item> 
相關問題