不幸的是,我有一个没有 Fragment 的视图 . 现在我需要在活动开始时显示 PopupWindow . 要显示弹出窗口,必须加载整个视图 . 在片段中,弹出窗口将显示在 onViewCreated 中 .

既然我没有片段,重做所有内容需要一些时间,是否有可能在活动开始时显示弹出窗口?

我见过如下建议:

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

当我尝试它时,没有显示弹出窗口 . 顺便问一下,这个解决方案真的100%安全吗?我看不到runnable在视图实际完成时会怎么知道?