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

穿精又带淫゛_ 提交于 2020-12-12 02:18:07

问题


My Activity contain three EditText and one button. I set custom AlertBox for get the User input on one EditText. When I click on OK button from Alert Box , Focus Automatically goes to First EditText.

I used

editext.clearFocus();

I also tried

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

But doesn't work.
How to remove focus in All EditText after click on OK from AlertDialog. Thanks in Advance.


回答1:


To clear focus and remove cursor from editText

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



回答2:


Try adding this in the root layout of your xml:

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



回答3:


This worked for me

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



回答4:


I am using this and it is working perfectly. On Clicking the option of submitting it will clear the focus and remove cursor on edit text.

getCurrentFocus().clearFocus();


来源:https://stackoverflow.com/questions/36305946/remove-focus-from-all-edit-text-after-click-on-ok-from-alert-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!