调用的onCreate对话框纯黑色画面时()对话框、画面、黑色、onCreate

2023-09-06 04:06:37 作者:ヤ未央мo寒メ

我已经在几个不同的应用程序这个问题,现在我似乎无法找到一个解决方案。

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 是pretty的直线前进......只是扩展了活动并有主题设置为 @android:款式/ Theme.Dialog 在清单文件

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

推荐答案

事实证明,这是一个的 1.5已知的bug (固定在1.6和1.1从来就不是一个问题)。从动画的新的活动发生之前,旧的活动已经绘该缺陷​​是由于,但如果它只是presents老活动是在任务的第一个活动。

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 /价值/的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>

然后,只需引用它在你的Andr​​oidManifest.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.