来自oncreate的android弹出窗口调用 [英] android popup window call from oncreate

查看:58
本文介绍了来自oncreate的android弹出窗口调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void loadingPopup() {
    LayoutInflater inflater = this.getLayoutInflater();
          View layout = inflater.inflate(R.layout.loading_dialog, null);

        PopupWindow windows = new PopupWindow(layout , 300,300,true);
       windows.setFocusable(false);
          windows.setTouchable(true); 
          windows.setOutsideTouchable(true);
          windows.showAtLocation(layout,Gravity.CENTER, 0, 0);

}

oncreate()调用方法loadingPopup()时发生了异常..请您帮忙

when invoke the method loadingPopup() from oncreate() an exception accrued .. please can you help me

推荐答案

您甚至试图在显示活动窗口之前显示弹出窗口. 借助post方法,我们可以等到所有必要的启动生命周期方法完成.

You are trying to show the pop-up window even before the activity window has been displayed. With the help of post method we can wait until all necessary start up life cycle methods get completed.

尝试一下:

private void loadingPopup() {
    LayoutInflater inflater = this.getLayoutInflater();
    final View layout = inflater.inflate(R.layout.loading_dialog, null);

    final PopupWindow windows = new PopupWindow(layout , 300,300,true);
    windows.setFocusable(false);
    windows.setTouchable(true); 
    windows.setOutsideTouchable(true);
    layout.post(new Runnable() {
        public void run() {
            windows.showAtLocation(layout,Gravity.CENTER, 0, 0);
        }
    });
}

这篇关于来自oncreate的android弹出窗口调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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