从警报对话框中单击确定后,从所有编辑文本中删除焦点

Remove focus from all Edit Text after click on OK from Alert Dialog

我的Activity包含三个EditText和一个按钮。 我设置自定义 AlertBox 以在一个 EditText 上获取用户输入。 当我单击 Alert Box 中的 OK 按钮时,焦点自动转到第一个 EditText。

我用过

editext.clearFocus();

我也试过了

editText.clearFocus();
editText.setEnabled(false);

但是不起作用。
从 AlertDialog 中单击“确定”后如何移除所有 EditText 中的焦点。 提前致谢。

尝试将此添加到 xml 的根布局中:

android:focusable="true"
android:focusableInTouchMode="true"

清除焦点并从 editText 中删除光标

editText.clearFocus();
editText.setFocusable(false);
editText.setFocusableInTouchMode(true);
editText.setCursorVisible(false);

这对我有用

public void clicked(View v)
{
    final AlertDialog.Builder alert=new AlertDialog.Builder(this);
    alert.setTitle("Hello");
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            editText.setFocusable(false);
        }
    });

    alert.create();
    alert.show();
}

我正在使用它,它运行良好。单击提交选项将清除焦点并移除编辑文本上的光标。

getCurrentFocus().clearFocus();