Can I always use lint ignore NewApi instead of different styles.xml files?

空扰寡人 提交于 2021-01-27 02:43:09

问题


I have two styles.xml, one in values another in values-v21 resource folders.

values/styles.xml content is:

<resources>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

values-v21/styles.xml content is:

<resources>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

Can I delete styles.xml file from values-v21 and add v21dedicated items with a lint tools: ignore="NewApi" property like this:

<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds" tools:ignore="NewApi">true</item>
        <item name="android:statusBarColor" tools:ignore="NewApi">@android:color/transparent</item>
    </style>
</resources>

Can I do that without any problem?

And if I can always do that what is the point of having two separated style.xml files?


回答1:


Because you may have different layout, or use different widgets based on Android api.

Some folks may discourage the use of tools:ignore="NewApi", citing concerns of hiding incompatible widget attributes.

My opinion is - it depends. If it is a trivial matter, why would I have to maintain separate sets of files?



来源:https://stackoverflow.com/questions/41980067/can-i-always-use-lint-ignore-newapi-instead-of-different-styles-xml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!