无法显示对话框/启动画面
我正在尝试使用此处讨论的对话框方法创建一个在我的应用程序初始化时显示的启动屏幕:
http://blog.iangclifton.com/2011/01/01/android-splash-screens-done-right/
然而,无论如何我这样做,启动画面永远不会出现,屏幕只是保持黑色,直到主屏幕完全实例化。我在 setup() 方法的末尾调用 m.dismiss() 。
不会引发错误,launch.XML 只是一个具有 match_parent 宽度和高度的线性布局,并带有一个占据 enti 视图的按钮,但它从未出现。
我认为它要么是“THIS”的上下文,要么是否则,或者宽度/高度应该是匹配父级以外的东西......任何想法/帮助将不胜感激。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m = new Dialog(this,R.style.SplashScreen);
m.setContentView(R.layout.launch);
m.setCancelable(false);
m.show();
setContentView(R.layout.main);
Handler h = new Handler();
h.post( new Runnable(){
public void run() {
// TODO Auto-generated method stub
setup();
}
});
启动.XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button android:text="Button" android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/button1"></Button>
</LinearLayout>
I am attempting to create a splash screen to show up while my app initializes, using the dialog method discussed here:
http://blog.iangclifton.com/2011/01/01/android-splash-screens-done-right/
Yet, no matter what I do, the splash screen never appears, the screen just stays black until the main screen fully instantiates.. I call m.dismiss() at the end of the setup() method.
No errors are thrown, and the launch.XML is simply a linearlayout with a match_parent width and height and with a button taking up the enti view, but it never appears..
I assume it is either the context of "THIS" should be something else, or the width/height should be something other than match parent... any ideas/help would be appreciated.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m = new Dialog(this,R.style.SplashScreen);
m.setContentView(R.layout.launch);
m.setCancelable(false);
m.show();
setContentView(R.layout.main);
Handler h = new Handler();
h.post( new Runnable(){
public void run() {
// TODO Auto-generated method stub
setup();
}
});
LAUNCH.XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button android:text="Button" android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/button1"></Button>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的设置方法在 UI 线程上运行。它会阻止显示启动屏幕。尝试使用 asynctask 进行设置,并消除 onPostExecute() 中的启动
your setup method is run on the UI thread. it prevents the spashscreen from being displayed. Try using an asynctask for the setup, and dismiss the splash in the onPostExecute()