Can Preview Window be changed dynamically at runtime after switching themes?


My english is poor, so I used gpt to help me discribe my issue. If it's difficult to understand, sorry.

I'm working on an Android application and I'm trying to change the appearance of the Preview Window (the window displayed before an Activity is fully created).

Background:

My application supports multiple themes. Users can change the theme at runtime.

For example:

  • Light Theme

  • Dark Theme

I apply the selected theme using:

setTheme(...)

The Activity UI itself updates correctly. All TextViews, backgrounds, and styles are changed as expected.

Problem:

During Activity transitions, I can still see a Preview Window with the old background color for a very short time before the Activity is displayed.

From my understanding, the Preview Window is created by the Android framework before Activity.onCreate() is executed.

My theme contains:

<item name="android:windowBackground">@drawable/background_xxx</item>

Questions:

  1. Is it possible to dynamically update the Preview Window at runtime?

  2. Can the Preview Window background be changed through code after the app is already running?

  3. Does Android cache the Preview Window based on the Activity theme?

  4. Is recreating/restarting the Activity sufficient, or is a full process restart required?

  5. Is the only reliable solution to use:

<item name="android:windowDisablePreview">true</item>

or a dedicated Splash Activity?

Expected behavior:

After the user changes the theme, I want future Activity launches/transitions to show the Preview Window with the new theme background instead of the old one. I don't want to cancel the Preview Window.

Any explanation about how Preview Window creation and theme updates work internally would be appreciated.

Environment:

  • Android Studio version: Android Studio Dolphin 2021.3.1 Patch 1

  • Virtual Device: Android_x86_4.4r5_KM0244

  • SDK: Android 4.2(Jelly Bean) API17

  • Java

0
Jun 9 at 9:48 AM
User Avatarカウコウ
#java#android

No answer found for this question yet.