Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the theme for the application, to avoid wrong color transitions?

Background

I'm developing a themes chooser feature in my "app manager" app, and I've succeeded setting the theme dynamically for each of the activities.

AGAIN : this is not about setting the theme for the activities. This actually works fine for me.

The problem

The acitivties are showing the correct theme, but the application itself, when launching the app, is showing the wrong one, no matter what I do.

This is a problem because when the user opens the app, he will see the background of the theme of the app, and only after a few moments the activity will be shown with the theme the user has chosen.

So, if the application has a white background, and the user has chosen a theme with a black background, the order will be:

Application shows a white background -> activity is starting and shows a black background.

In screenshots:

enter image description here

So this is wrong. In this case, I need it to show black-to-black background.

Only if the user has chosen a Holo-light based theme (which the app has by default), it works fine, as the color matches the one on the activity that is shown right when opening the app.

What I've tried

I had an idea of setting the app's theme to be empty of everything, hoping that no transition will be shown, using something like:

<application
    ...
    android:theme="@android:style/Theme.Translucent.NoTitleBar" >

In fact, some people here suggested a similar solution.

This works, but it causes a bad experience, since on some devices it takes some time till the first activity is shown, and as such, there is a significant amount of time the user sees nothing at all, as if the app isn't being launched.

The question

How do I solve this?

I've already tried setting the theme in the class that extends from Application, but it doesn't do anything, no matter where in this class I call it.

like image 572
android developer Avatar asked Apr 20 '14 15:04

android developer


People also ask

How do I change my theme to normal?

Settings. Under Display Options, tap Theme. Select the theme for this device: Light—White background with dark text.

How do I manage Dark mode on Android?

Use the system setting (Settings -> Display -> Theme) to enable Dark theme. Use the Quick Settings tile to switch themes from the notification tray (once enabled). On Pixel devices, selecting the Battery Saver mode enables Dark theme at the same time.


1 Answers

A bit late, but this may be the answer. I discovered it by chance.

No entrance activity, no custom animations, no hacking. Simply an attribute in theme. Android buried this deep inside its resources.

Add the following attribute to your app theme:

<!--
  ~ From Theme.NoDisplay, this disables the empty preview window probably
  ~ with an incorrect theme.
  -->
<item name="android:windowDisablePreview">true</item>

And your are done. Enjoy it!

like image 151
Hai Zhang Avatar answered Oct 20 '22 20:10

Hai Zhang