Currently, I do provide 2 theme in my app, based on user last choice - dark theme and light theme.
During main activity start-up, I will do the following.
public class MyFragmentActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// getUserLastThemeChoice will either return R.style.Theme_My_Light or
// R.style.Theme_My_Dark.
this.setTheme(getUserLastThemeChoice());
super.onCreate(savedInstanceState);
In my AndroidManifest.xml
, I have the following
<application
...
android:theme="@style/Theme.My.Dark" >
Due to the hard-coded value in AndroidManifest.xml
, if user previous choice is light theme, I will observed the following.
- App start up with dark theme, due to
AndroidManifest.xml
- A while...
- App will change to white theme due to
this.setTheme
in mainActivity
In there any way I can avoid such transition observation? That's it, just present to user directly, based on their last choice.
p/s Note, it wouldn't help much if you remove the theme information from manifest. As the system is going to use holo dark by default. You will still observe the transition, especially in slow device.
I know this is very old but maybe it still helps:
If you set the activity's theme to
it'll not show that initial screen. Instead it'll just take a bit more for the app to show anything at all.
Hiding theme manipulation, particularly on app start up is tricky. Unfortunately there is no way to consistently remove that initial transition, because there's no telling how fast/slow the device running it is. Android will always show that blank background in the default theme before inflating the layout for the main activity.
But there is a trick to hiding it. A splash screen that appears when the user opens the app, and fades out after the initial activity has loaded. This way the splash screen hides the theme transition, without jarring the user. Splash screens receive some well deserved hate, but a situation like this does justify their use. Again, I don't know the specifics of your app, but you have to weigh the pros/cons of having a splash screen and smooth transition vs. no splash screen and a jarring transition.
There are loads of ways of implementing splash screens. In your case I would try to create a launcher activity, with a neutral theme, and apply a smooth animation for the transition between the splash screen and your main activity like so:
And the animations: