在onCreate()中调用对话框时,实体黑屏 [英] Solid black screens when calling Dialogs in onCreate()

查看:93
本文介绍了在onCreate()中调用对话框时,实体黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在几个不同的应用程序中遇到了这个问题,我似乎找不到解决方案。

I've had this problem in a few different apps now and I can't seem to find a solution.

如果在onCreate() 活动,我开始一个使用对话主题的活动,它不绘制任何东西来屏幕...整个屏幕保持黑色。所有的意见都在那里(例如,我可以点击哪里一个 EditText 应该是,它会给我键盘),它们只是不可见。

If, in the onCreate() of an Activity, I start an activity that uses the dialog theme it doesn't draw anything to screen... the whole screen stays black. All the views are there (e.g., I can tap where an EditText should be and it'll give me the keyboard), they're just not visible.

任何人都有任何想法?

愚蠢的简单例子,为了好玩:

Stupid simple example, for fun:

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.main);
        startActivityForResult(new Intent(this, CredentialsInputActivity.class), 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // do some crap with the result, doesn't really matter what
    }
}

CredentialsInputActivity 非常简单,只需扩展活动并具有主题集到 @android:style / Theme.Dialog 在清单文件中。

CredentialsInputActivity is pretty straight forward... just extends Activity and has the theme set to @android:style/Theme.Dialog in the manifest file.

推荐答案

p>事实证明,这是一个已知错误在1.5(固定在1.6,从来没有在1.1中的问题)。该错误源自在旧活动绘制之前发生的新活动的动画,但仅当旧活动是任务中的第一个活动时才会显示。

It turns out that this is a known bug in 1.5 (fixed in 1.6 and never a problem in 1.1). The bug stems from the animation for the new Activity taking place before the old Activity has been drawn, but it only presents if the "old" Activity was the first Activity in the Task.

解决方法是禁用主题的动画。使用扩展主对话框主题的新主题来做到这一点的最简单的方法。

A workaround is to disable the animation for the theme. The simplest way to do this it with a new theme that extends the main dialog theme.

res / values / themes.xml:

res/values/themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CupcakeDialog" parent="android:Theme.Dialog">
        <item name="android:windowAnimationStyle">@null</item>
    </style>
</resources>

然后在AndroidManifest.xml中引用它:

Then just reference it in your AndroidManifest.xml:

<!-- ... -->
<activity 
    android:name=".CredentialsInputActivity"
    android:label="@string/CredentialsInputActivity_window_title"
    android:theme="@style/CupcakeDialog" />
<!-- ... -->

显然,您松动了动画,但至少可以看到它:)

Obviously, you loose the animation, but at least you can see it :)

注意:commonsware.com的解决方案也很好,我在评论中注意到了。

Note: commonsware.com's solution worked fine too with the caveat I noted in the comments.

这篇关于在onCreate()中调用对话框时,实体黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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