Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android change style dynamically

I've describef properties of my objects (nevermind what the object is) in styles.xml. I would like to change these properties dynamically in styles.xml.

Does anybody know how can I do that?

like image 332
davs Avatar asked Jan 21 '23 21:01

davs


2 Answers

You can do that like:

In Activity:

this.setTheme(R.style.ThemeRed);

In styles.xml:

<resources>
  <style name="ThemeBlack" parent="@android:style/Theme">
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:typeface">sans</item>
    <<item name="android:background">#999999</item>
    <item name="android:textSize">16sp</item>
  </style>
  <style name="ThemeRed" parent="@android:style/Theme">
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:typeface">sans</item>
    <item name="android:background">#c81111</item>
    <item name="android:textSize">16sp</item>
  </style>
</resources>
like image 67
Masatomo Nakano Avatar answered Feb 04 '23 15:02

Masatomo Nakano


I am seeing contradicting answers to this question. This says yes, but this says no. I looked at the android docs for the View and can not find any setStyle method.

like image 40
Ryan Conrad Avatar answered Feb 04 '23 13:02

Ryan Conrad