安卓:设置窗口的背景上展开活动 [英] Android: Setting Window Background on launched Activity
问题描述
所以,我读过罗曼盖伊的博客文章上设置窗口背景和percieved性能,并正尝试模仿的。它是这样一个简单的解决方案,不知道为什么我不能得到这个工作,但活动只是拒绝回升定向背景。
So I've read Romain Guy's blog post on setting the Window background and percieved performance, and am trying to emulate that. It is such a simple solution and not sure why I can't get this working, but the activity simply refuses to pick-up the directed background.
我有一个ListView的onListItemClick启动一个新的活动,即需要3-5秒,完全负荷。当用户在等待,我想画一个windowBackground,让他们'看'的活动是真的准备好了。这是我的code:
I have a ListView that onListItemClick launches a new Activity, one that takes 3-5 seconds to fully load. While the user is waiting, I'd like to draw a windowBackground so that they 'see' the activity before it is actually ready. Here's my code:
AndroidManifest片段的推出活动:
AndroidManifest snippet for the launched Activity:
<activity
android:name=".activity.EditorActivity"
android:screenOrientation="portrait"
android:windowBackground="@drawable/background_editor">
对于EditorActivity的XML布局:
The XML layout for the EditorActivity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/editor"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="Editor" />
</FrameLayout>
最后,绘制的清单,background_editor.xml被设置:
And finally, the drawable being set in the Manifest, background_editor.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/editor_bg"
android:tileMode="repeat" />
editor_bg是位于.png文件的诠释,他绘制的文件夹。
editor_bg is a .png file located int he drawable folder.
最后的结果是被推出的EditorActivity,而我看到的是默认的黑色背景,白色显示的编辑文本(我补充说,测试的XML文件被正确加载。
The end result is the EditorActivity gets launched, and all I see is the default black background with the "Editor" text displayed in white (I added that to test that the XML file was loading correctly.
我也试着通过Android上的FrameLayout和TextView的背景设置为透明:背景=@机器人:彩色/透明,想着也许他们默认为黑色背景,但没有运气
I've also tried setting the background of the FrameLayout and TextView to transparent via android:background="@android:color/transparent", thinking maybe they were defaulting to a black background, but no luck.
这是一个漫长的几天,我敢肯定,我失去了一些东西简单...任何明显的失误我想提出?
It's been a long few days, I'm sure I am missing something simple... any obvious mistakes I am making here?
推荐答案
尝试设置窗口背景编程方式推出新的活动之前。
Try setting window background before launching the new activity programmatically.
getWindow().setBackgroundDrawableResource(R.drawable.my_drawable);
这篇关于安卓:设置窗口的背景上展开活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!