Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.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 使用AppCompact时是否需要特定于版本的样式项?_Android_Styles_Android Appcompat - Fatal编程技术网

Android 使用AppCompact时是否需要特定于版本的样式项?

Android 使用AppCompact时是否需要特定于版本的样式项?,android,styles,android-appcompat,Android,Styles,Android Appcompat,请检查选项1和选项2,在values-v21样式中定义特定于平台的样式属性(如android:colorPrimary)有什么好处 values/styles.xml <resources> <!-- Base application theme. --> <style name="AppTheme" parent="CommonTheme"> </style> <style name="CommonThe

请检查选项1和选项2,在values-v21样式中定义特定于平台的样式属性(如
android:colorPrimary
)有什么好处

values/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:values-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>
<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:values-v21/styles.xml-编写平台特定的样式属性以及继承

<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>
<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完全没有必要,因为AppCompat本身会复制颜色,如其:


?属性/颜色初级
?属性/原色暗
?属性/颜色重音
?属性/颜色控制正常
?属性/颜色控制激活
?属性/颜色控制突出显示
?属性/颜色按钮正常

选项2完全没有必要,因为AppCompat本身会复制颜色,如其:


?属性/颜色初级
?属性/原色暗
?属性/颜色重音
?属性/颜色控制正常
?属性/颜色控制激活
?属性/颜色控制突出显示
?属性/颜色按钮正常