1

我有一个 BaseActivity 可以在其代码上打开 Dialogs,但是我无法更改此类代码,因此我在子类上对其进行了扩展,如何知道 Dialog 何时打开?

4

2 回答 2

1

您可以尝试覆盖onCreateDialog(). 这会传递一个在 Activity 调用时使用的参考 ID showDialog(id)。如果您只需要知道是否Dialog要显示任何内容,那么我想您可以调用 super 它将返回将显示的对话框。

@Override
protected Dialog onCreateDialog(int id){
   Dialog dialogToBeShown = super.onCreateDialog(id);
   if(dialogToBeShown != null){
      ***Do whatever you have to with the dialog***
   }
   return dialogToBeShown;
}

编辑:

这只会在第一次创建对话框时起作用。您可以执行类似的操作,onPrepareDialog(int id, Dialog dialog, Bundle args)在打开对话框时始终调用它。

于 2011-09-20T17:22:02.150 回答
0

Dialog has an isShowing() method that should return if the dialog is currently visible. So you can use that to see if a dialog is showing and hide it with dismissDialog(). You just have to keep a reference to the Dialogs you create in onCreateDialog().

于 2011-09-20T14:27:34.817 回答