实施变更的黑/浅主题,Android应用程序的功能应用程序、功能、主题、Android

2023-09-05 05:41:15 作者:我的男神是个帅比

我想在我的应用程序中的改变主题功能。如果我叫setTheme()中的onCreate(),有一个问题。

I want to have a "change theme" feature in my app. If I call setTheme() in onCreate(), there is one problem.

我启动我的应用程序后的那一刻,纯白色背景出现第二次(因为我已经把光的主题在清单)。在这之后,会显示我的活动的完整布局 - 它可以是白色或黑色的背景,根据用户的主题preference

The moment after I launch my app, a plain white background appears for a second (because I have set light theme in the manifest). After that, the complete layout of my Activity is displayed - it is either with white or black background, according to user's theme preference.

有没有办法白色或黑色的背景是否会出现在发射后?我可以改变

Is there any way I can change whether white or black background appears after launch?

推荐答案

请确保你调用 setTheme()的onCreate()在调用的setContentView()。然后,如果你想动态稍后再次更改主题,你应该简单地重新启动您的活动。

Make sure you call setTheme() in onCreate() BEFORE calling setContentView(). Then if you want to dynamically change the theme again later, you should simply restart your activity.