android popup window call from oncreate

前端 未结 1 1263
醉话见心
醉话见心 2021-01-14 05:02
private void loadingPopup() {
    LayoutInflater inflater = this.getLayoutInflater();
          View layout = inflater.inflate(R.layout.loading_dialog, null);

              


        
1条回答
  •  孤城傲影
    2021-01-14 05:32

    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.

    Try this :

    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);
            }
        });
    }
    

    0 讨论(0)
提交回复
热议问题