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