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

时间:2016-03-30 10:19:29

标签: android android-edittext focus highlight

我的活动包含三个EditText和一个按钮。 我设置自定义AlertBox以获取一个EditText上的用户输入。 当我点击Alert Box中的OK按钮时,Focus Automatically会转到First EditText。

我用过

editext.clearFocus();

我也试过

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

但是没有用。
单击AlertDialog中的OK后,如何在All EditText中删除焦点。 在此先感谢。

4 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

尝试在xml的根布局中添加它:

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

答案 2 :(得分:0)

这对我有用

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

答案 3 :(得分:0)

我正在使用它并且它工作得很好。单击提交选项将清除焦点并删除编辑文本上的光标。

getCurrentFocus().clearFocus();