如何设置主题,为应用程序,以避免错误的色彩过渡? [英] How to set the theme for the application, to avoid wrong color transitions?

查看:160
本文介绍了如何设置主题,为应用程序,以避免错误的色彩过渡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个主题选择器功能在我的 应用程序管理器应用 ,我已经成功了动态设定主题为每个活动。

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.

在acitivties都显示了正确的主题,但应用程序本身,启动应用程序时,正显示出错误的,无论我做什么。

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.

在截图:

所以,这是错误的。在这种情况下,我需要它,以显示黑到黑背景

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.

我有设置应用​​程序的主题是空的一切,希望没有过渡将显示,使用类似的想法:

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.

我要如何解决这个问题?

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.

推荐答案

我最初的建议是,用一个透明的全屏幕应用程序的主题(无操作栏)。

Transparent application theme with fade-in animation

My original suggestion was to use a Transparent full screen application theme (no action bar).

结合,我总是建议α-动画从应用主题活动主题褪色跨越。这prevents不和谐给用户的操作栏出现时。

Combined with that, I always suggest an alpha-animation to fade across from the application theme to the activity theme. This prevents jarring to the user when the action bar appears.

OP的code将保持几乎相同,不同的是改变明显的主题,并加入了奥飞动漫的一些基本活动类的的onCreate()方法在下面的例子:

OP's code would remain almost identical, except for changing the manifest theme, and adding the alpha animation in your onCreate() method of some base activity class as in examples below:

定义为表现主题:

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

基地活动的onCreate()方法:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // set your custom theme here before setting layout
    super.setTheme(android.R.style.Theme_Holo_Light_DarkActionBar);

    setContentView(R.layout.activity_main);

    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}

在基本淡出:

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />

基本淡出(不是真的需要,但出于完整性):

basic fade out (not really needed, but for completeness):

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromAlpha="1.0"
    android:toAlpha="0.0" />

当然,动画的持续时间这里的路比你投入生产 - 他们是长,所以你可以看到他们在开发阶段

Of course the animation durations here are way longer than you'd put in production - they are long so you can see them in your development stages.

据随后由@EmanuelMoecklin评论已经指出,@androiddeveloper,这被认为是。它也包括在由牙鲷的答案。然而,由于OP状态,特别是在旧设备的缺点是,用户没有得到反馈,当他们尝试启动应用程序。它出现在应用程序时间过长推出。

It has been noted subsequently in comments by @EmanuelMoecklin, @androiddeveloper that this was considered. It is also included in answer by dentex. However, as the OP states, the weakness particularly on older devices is that the user gets no feedback when they try to launch the app. It appears the app takes too long to launch.

在奇巧,不是这种情况下,由于在状态栏&安培;软键从透明到黑色的变化,而屏幕的其余部分仍然是透明的。

On KitKat, this is not the case, since the status bar & soft-keys change from transparent to black, while the rest of the screen is still transparent.

另取这种方法是使用一个全屏幕的黑色背景,应用主题。这是由 Bitspin 获得的及时,谁被收购了谷歌显然在该应用程序令人惊叹的用户界面的基础。因此,似乎该方法在许多情况下完全可以接受的。

Another take on this approach would be to use a full-screen black background as the application theme. This is what was done by Bitspin for Timely, who were bought by Google apparently on the basis of the stunning UI in that app. It seems this method is therefore quite acceptable in many cases.

为了加快推出的感知,替代了纯黑色的主题是使用全屏图像应用程序的徽标中心 - 闪屏的风格。再次衰落横跨一次推出的活动。

In order to speed up the perception of the launch, an alternative to the plain black theme is to use a full-screen image with the app's logo in the centre - "splash screen" style. Again fading across to the activity once launched.

这是不可能的,透明的主题,利用透明全屏图像。机器人忽视了图像的透明度(或覆盖在透明图像投影到黑色背景)。这所指出的OP中的注释。

This is not possible for the transparent theme, using a transparent full-screen image. Android ignores the transparency of the image (or overlays the transparent image onto a black background). This was pointed out by OP in the comments.

我们可以有一个透明的主题没有图像,或不透明的主题与图像(另外一个问题一个有趣的话题也许)。

We can either have a transparent theme without an image, or an opaque theme with an image (an interesting topic for another question perhaps).

另一项建议由@ sergio91pt 是使用别名不同的活动清单。

Another suggestion by @sergio91pt is to use aliases for different activities in the manifest.

虽然这可能是在某些情况下,有用的技术,在这种情况下,它也有一些缺点:

While this can be a useful technique in some circumstances, in this case it has some drawbacks:

  1. 在任何家庭屏幕快捷方式用户的活动将停止工作时,主发射别名改变即每个用户更改主题时创建的。
  2. 在某些设备/发射器的激活和放大器相当慢;停用不同的别名。在我的经验,这可能需要几秒钟(Galaxy Nexus的4.1 IIRC),在此期间,您可能已没有明显的启动图标,或者你有2个图标。
  3. 每个可能主题需要一个不同的别名 - 这可能是很麻烦的,如果有许多不同的主题

这篇关于如何设置主题,为应用程序,以避免错误的色彩过渡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆