我的应用程序中有一个DialogFragment(android.support.v4.app.DialogFragment)的子类,它很长一段时间都运行良好。该对话框本身是在onCreateDialog()回调中构建的。Android:支持DialogFragment,自定义布局未显示
但是,现在我想转换到新的对话框布局,并决定构建一个完全自定义的对话框。据我所知,这需要删除覆盖onCreateDialog()和回调的View层次结构。我这样做了。
产生的行为是非常奇怪 - 当对话框需要显示时,屏幕会变暗,但该对话框的布局不显示(“后退”按钮的行为也符合对话的功能):
我试图恢复到旧的实现(它使用onCreateDialog()回调) - 它仍然有效。
我的问题是:我做错了什么?
Dialog的代码:
/**
* A dialog that can show title and message and has two buttons. User's actions performed
* in this dialog will be posted to {@link EventBus} as {@link PromptDialogDismissedEvent}.
*/
public class PromptDialog extends BaseDialog {
/* package */ static final String ARG_TITLE = "ARG_TITLE";
/* package */ static final String ARG_MESSAGE = "ARG_MESSAGE";
/* package */ static final String ARG_POSITIVE_BUTTON_CAPTION = "ARG_POSITIVE_BUTTON_CAPTION";
/* package */ static final String ARG_NEGATIVE_BUTTON_CAPTION = "ARG_NEGATIVE_BUTTON_CAPTION";
@Inject EventBus mEventBus;
private TextView mTxtTitle;
private TextView mTxtMessage;
private Button mBtnPositive;
private Button mBtnNegative;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);</