This is a pretty basic question - I am supporting API versions 11+ and I want to use functionality on phones that have a newer API version. However, it would be nice if I didn't have to re-define my style. So, for example, if, in values/styles.xml I have:
<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>
and then in values-v14/styles.xml I have:
<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.MyApp.Input.Text">
<item name="android:textAllCaps">true</item>
</style>
</resources>
Then, on devices that have API 14+, I'll get the union of the two styles.
A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view. When you apply a theme, every view in the app or activity applies each of the theme's attributes that it supports.
xml in the your application's res/values directory. Add a root <resources> node. For each style or theme, add a <style> element with a unique name and, optionally, a parent attribute. The name is used for referencing these styles later, and the parent indicates what style resource to inherit from.
Defining Styles This XML file resides under res/values/ directory of your project and will have <resources> as the root node which is mandatory for the style file.
The question is quite old but it is possible: The following snippet is from 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>
If you want to inherit (for eg) the same style and specialize in the API >=23 you must define a values/style-23.xml as below:
<style name="AppTheme.AppTheme23" >
<item name="android:windowLightStatusBar">true</item>
</style>
Obviously in the AndroidManifest.xml the theme to specify is:
android:theme="@style/AppTheme"
That's all folks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With