对主题样式进行API相关的引用

时间:2017-02-11 20:44:44

标签: android android-resources android-theme android-styles qualifiers

API 21 +:

android:background="?android:attr/selectableItemBackgroundBorderless"

API< 21:

android:background="?android:attr/selectableItemBackground"

怎么可能?

我知道使用"?attr/API_dependent_theme_reference"的解决方案,例如this。不幸的是,这不适用于 App Widget布局

另外,我知道解决方案使用style="..." viewvaluesvalues-v21文件夹中的多个样式定义。但是寻找一种直接分配background属性的方法(特别是Android,不幸的是,不支持分配多种样式,如CSS:class="style1 style2 etc"!)。

1 个答案:

答案 0 :(得分:0)

您可以拥有两个自定义绘图

抽拉/ backround_name.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="?android:attr/selectableItemBackground"
</layer-list>

可绘制-V21 / backround_name.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="?android:attr/selectableItemBackgroundBorderless"
</layer-list>