Android Question Switch custom material theme on run time

Pendrush

Well-Known Member
Licensed User
Longtime User
I have two themes for app, manifest look like:
B4X:
CreateResource(values, theme.xml,
<resources>
    <style name="ThemeLight" parent="@android:style/Theme.Holo.NoActionBar">
    </style>   
</resources>)

CreateResource(values-v21, theme.xml,
<resources>
  <style name="ThemeLight" parent="@android:style/Theme.Material.Light">
       <item name="android:windowNoTitle">true</item>
       <item name="android:windowActionBar">false</item>
       <item name="android:textColor">#000000</item> <!-- menu text,, msgbox title -->
       <item name="android:textColorSecondary">#AAAAAA</item> <!-- inactive editText line,, scrollbar -->
       <item name="android:colorPrimary">#1976D2</item> <!-- action bar -->
       <item name="android:colorPrimaryDark">#EEEEEE</item> <!-- status bar -->
       <item name="android:colorAccent">#1976D2</item> <!-- checkboxes,, switches,, etc. -->
       <item name="android:colorControlNormal">#AAAAAA</item> <!-- inactive checkboxes -->
   </style>
</resources>)

CreateResource(values, themedark.xml,
<resources>
    <style name="ThemeDark" parent="@android:style/Theme.Holo.NoActionBar">
    </style>   
</resources>)

CreateResource(values-v21, themedark.xml,
<resources>
  <style name="ThemeDark" parent="@android:style/Theme.Material">
       <item name="android:windowNoTitle">true</item>
       <item name="android:windowActionBar">false</item>
       <item name="android:textColor">#FFFFFF</item> <!-- menu text,, msgbox title -->
       <item name="android:textColorSecondary">#AAAAAA</item> <!-- inactive editText line,, scrollbar -->
       <item name="android:colorPrimary">#1976D2</item> <!-- action bar -->
       <item name="android:colorPrimaryDark">#000000</item> <!-- status bar -->
       <item name="android:colorAccent">#1976D2</item> <!-- checkboxes,, switches,, etc. -->
       <item name="android:colorControlNormal">#AAAAAA</item> <!-- inactive checkboxes -->
   </style>
</resources>)

If I set SetApplicationAttribute(android:theme, "@style/ThemeDark") only dark theme work, same is for light SetApplicationAttribute(android:theme, "@style/ThemeLight"), only light theme work.
I'm not able to switch between those two themes on run time with this example: https://www.b4x.com/android/forum/threads/changing-the-theme-at-runtime.57277/#content

Anyone know proper way or solution?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
The value of res.GetResourceId("style", "android:style/ThemeLight") and res.GetResourceId("style", "android:style/ThemeDark") is always zero.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The value of res.GetResourceId("style", "android:style/ThemeLight") and res.GetResourceId("style", "android:style/ThemeDark") is always zero.
It does work with the theme from post #1

B4X:
SetTheme(res.GetResourceId("style", "ThemeLight"))
 
Upvote 0
Top