android - 如何继承不同api版本指定的样式

标签 android android-styles

这是一个非常基本的问题 - 我支持 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/

相关文章:

android - Firebase 推送通知在后台振动

android - 如何在Android TextView中显示HTML文本?

Android:使用一般样式应用边距不起作用

android - 如何在 Action Bar 中设置粗体标题?

android - 如何更改 PreferenceScreen 中 PreferenceCategory 分隔符的颜色

android - RecyclerView : How to clear the recycled views from RecyclerView. 回收 View 池

android - 将捕获图像保存在 SD 卡中 android

java - Android 将 ArrayList<Integer> 保存到本地存储

android - 为什么我的 ImageButton 样式没有应用到我的 ImageButton?

android - 如何更改 ListPreference 按钮颜色?