Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...