Android Question again on changing theme at runtime

giggetto71

Active Member
Licensed User
Longtime User
Hi,
I went through this below example

https://www.b4x.com/android/forum/threads/changing-the-theme-at-runtime.57277/#content

the example works just fine but there is one thing I would like to change:
the app allows to change the theme at runtime and it saves the last choice so if one choose material light for example sets them theme to material light and at next start it will keep that theme. good. my issue is that because in the example the manifest has:

B4X:
CreateResourceFromFile(Macro, Themes.DarkTheme)

regardless the theme selected in the app, the app shows a black flash before loading the light theme. of course if I set the light theme in the manifest I always get a white flash before the app is loaded.
is there a way to avoid that and keep the intial "flash" consistent with the runtime choice?
 

giggetto71

Active Member
Licensed User
Longtime User
thanks. could you tell me how to customize the background of the lighttheme to be neutral ? thanks!
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
I actually found a way to link the windows background color to the phone mode! basically I created a new resource called "values-night" in the manifest which apparently android uses when the phone is in night mode.


B4X:
SetApplicationAttribute(android:theme, "@style/LightTheme")
CreateResource(values, colors.xml,
<resources>
   <color name="actionbar">#FFFFFFFF</color>
   <color name="statusbar">#ff006db3</color>
   <color name="textColorPrimary">#ffffffff</color>
   <color name="navigationBar">#ff006db3</color>
   <color name="custcolor">#ff00ff00</color>
</resources>
)
CreateResource(values, theme.xml,
<resources>
    <style name="LightTheme" parent="@android:style/Theme.Material.Light">
        <item name="android:windowBackground">@color/custcolor</item>
        <item name="android:colorPrimary">@color/actionbar</item>
        <item name="android:colorPrimaryDark">@color/statusbar</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:navigationBarColor">@color/navigationBar</item>
    </style>
</resources>
)

CreateResource(values-night, colors.xml,
<resources>
   <color name="actionbar">#FFFFFFFF</color>
   <color name="statusbar">#ff006db3</color>
   <color name="textColorPrimary">#ffffffff</color>
   <color name="navigationBar">#ff006db3</color>
   <color name="custcolor">#00000000</color>
</resources>
)
CreateResource(values-night, theme.xml,
<resources>
    <style name="LightTheme" parent="@android:style/Theme.Material.Light">
        <item name="android:windowBackground">@color/custcolor</item>
        <item name="android:colorPrimary">@color/actionbar</item>
        <item name="android:colorPrimaryDark">@color/statusbar</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:navigationBarColor">@color/navigationBar</item>
    </style>
</resources>
)
 
Upvote 0
Top