2015-04-25 40 views
5

这是一个非常基本的问题 - 我支持API版本11+,我想在具有更新API版本的手机上使用功能。不过,如果我不需要重新定义我的风格,那就太好了。因此,举例来说,如果在价值观/ styles.xml我:如何从不同的api版本指定的风格继承

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

,然后在值-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+的设备,我会得到两种风格的联合。

回答

2

的问题是很老,但它是可能的: 下面的片段是从价值观/ 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你必须定义一个值/风格23.xml如下:在AndroidManifest.xml

<style name="AppTheme.AppTheme23" > 
    <item name="android:windowLightStatusBar">true</item> 
</style> 

显然指定的主题是:

android:theme="@style/AppTheme" 

这就是所有人!