I have one app theme and many custom styles for different View
.
For example, snippet of code:
<!-- styles.xml -->
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light" />
<style name="title">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">22sp</item>
<item name="android:padding">10sp</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:textColor">@color/black</item>
<item name="android:background">@color/background_all_screen</item>
</style>
<style name="label">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">18sp</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_marginLeft">5dp</item>
</style>
<style name="button">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">2dp</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">@color/white</item>
<item name="android:background">@color/blue</item>
</style>
And now I want make many color themes for application. This is mean, that in different color themes custom View
was in different colors.
For example, in one color theme button is blue, in another - red.
How can I implement this resources for easy change of theme? There is a useful tutorial, but what about the custom styles for elements?
UPDATE: I try it, but this is nor work:
<style name="Button.MyButton" parent="android:style/Widget.Button">
<item name="android:background">@drawable/shape</item>
</style>
<style name ="Button.MyButton.Theme1">
<item name="android:textColor">#000000</item>
</style>
<style name ="Button.MyButton.Theme2">
<item name="android:textColor">#FFFFFF</item>
</style>
<Button
android:id="@+id/save_button"
android:layout_width="0px"
style="@style/Button.MyButton"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/save"/>