这是一个非常基本的问题 - 我支持 API 版本 11+,我想在具有较新 API 版本的手机上使用功能。但是,如果我不必重新定义我的风格就好了。因此,例如,如果在 values/styles.xml 我有:
<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.MyApp.Input.Text">
<item name="android:layout_width">match_parent<item>
<item name="android:layout_height>wrap_content</item>
</style>
</resources>
然后在 values-v14/styles.xml 我有:
<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.MyApp.Input.Text">
<item name="android:textAllCaps">true</item>
</style>
</resources>
然后,在具有 API 14+ 的设备上,我将获得两种样式的联合。
最佳答案
这个问题很老但是有可能: 以下 fragment 来自 values/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/dark</item>
<item name="colorAccent">@color/green</item>
<item name="checkboxStyle">@style/AppTheme.CheckBox</item>
</style>
如果您想继承(例如)相同的样式并专注于 API >=23,您必须定义一个 values/style-23.xml,如下所示:
<style name="AppTheme.AppTheme23" >
<item name="android:windowLightStatusBar">true</item>
</style>
显然在 AndroidManifest.xml 中指定的主题是:
android:theme="@style/AppTheme"
这就是所有人!
关于android - 如何继承不同api版本指定的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29859427/