我阅读了Romain Guy在博客文章中有关设置窗口背景和感知性能的内容,并尝试模仿它。 这是一个非常简单的解决方案,但我不确定为什么无法使其工作,因为活动简单地拒绝选择指定的背景。
我有一个ListView,当onListItemClick被触发时,会启动一个新的Activity,需要3-5秒才能完全加载。 在用户等待的同时,我想绘制一个windowBackground,以便他们在实际准备好之前就可以'看到'该活动。 这是我的代码:
所启动的活动的AndroidManifest片段:
<activity
android:name=".activity.EditorActivity"
android:screenOrientation="portrait"
android:windowBackground="@drawable/background_editor">
EditorActivity的XML布局:
<?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>
最后,在 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是位于drawable文件夹中的.png文件。
最终结果是启动EditorActivity并且我只看到了默认的黑色背景和白色显示的"Editor"文本(我添加了这个来测试XML文件是否正确加载)。
我也尝试过通过android:background="@android:color/transparent"将FrameLayout和TextView的背景设置为透明,以为它们可能默认为黑色背景,但没有成功。
已经过去了几天,我肯定错过了一些简单的东西...我在这里犯了什么明显的错误吗?