I styled specific TextViews and other stuff with styles. Now I want to implement another theme, which should change espacially the colors which are defined in styles.xml. So is it possible to add all of those styles to a theme and change it on runtime maybe with act.setTheme(themeID);?
Here are some code samples:
ListView Layout.xml (Looks a little bit chaotic but the style attributes should be easy to find.)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/OrangeTheme_ListView_Item"
android:id="@+id/MainListItemBG" android:padding="10dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_width="fill_parent">
<TextView
style="@style/OrangeTheme_ListView_Item_TextHead"
android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/MainList_Head" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TableLayout android:stretchColumns ="*" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableLayout1">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
style="@style/OrangeTheme_ListView_Item_TextBody"
android:layout_width="fill_parent" android:text="test"
android:layout_height="fill_parent" android:id="@+id/MainList_Body_Left"></TextView>
<TextView
style="@style/OrangeTheme_ListView_Item_TextBody" android:layout_width="fill_parent" android:text="test" android:layout_height="fill_parent" android:id="@+id/MainList_Body_Right"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
A part of my styles.xml
<style name="OrangeTheme_ListView">
<item name="android:background">#FFFFFF</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:divider">#FFFFFF</item>
<item name="android:dividerHeight">5dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:cacheColorHint">#00000000</item>
</style>
<style name="OrangeTheme_ListView_Item">
<item name="android:background">@drawable/orange_theme_lv_bg</item>
<item name="android:textColor">#000000</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_marginTop">10dp</item>
</style>
<style name="OrangeTheme_ListView_Item_TextHead">
<item name="android:textColor">#000000</item>
</style>
<style name="OrangeTheme_ListView_Item_TextBody">
<item name="android:textColor">#000000</item>
<item name="android:textSize">12sp</item>
</style>
Unfortunately you can’t change styles at runtime, yet. Here
is the explanation, why. What you can do is to create different layouts and load them according to the situation your App is in.