【问题标题】:Hide AlertDialog's OK and Cancel buttons隐藏警报对话框确定和取消按钮
【发布时间】:2019-04-27 22:20:05
【问题描述】:

我想从我的 AlertDialog 中隐藏按钮。我找到了this 解决方案,但它只是禁用了按钮。

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    ...
    AlertDialog dialog = builder.create();
    Button button = dialog.getButton(Dialog.BUTTON_POSITIVE);
    button.setEnabled(false);

    return dialog;
}

【问题讨论】:

    标签: android dialog


    【解决方案1】:

    您必须将按钮的可见性设置为 GONE 而不是使用setEnabled()。此外,您必须在对话框的onStart() 中执行此操作,如下所示:

    @Override
    public void onStart() {
        super.onStart();
    
        AlertDialog d = (AlertDialog) getDialog();
        if (d != null) {
            Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
            Button negativeButton = d.getButton(Dialog.BUTTON_NEGATIVE);
            positiveButton.setVisibility(View.GONE);
            negativeButton.setVisibility(View.GONE);
        }
    }
    

    【讨论】:

    • 这里只想说,不要以第三人称视角回答。
    猜你喜欢
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多