Skip to content Skip to sidebar Skip to footer

Remove Focus From All Edit Text After Click On Ok From Alert Dialog

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

Solution 1:

To clear focus and remove cursor from editText

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

Solution 2:

Try adding this in the root layout of your xml:

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

Solution 3:

This worked for me

publicvoidclicked(View v)
{
    final AlertDialog.Builder alert=newAlertDialog.Builder(this);
    alert.setTitle("Hello");
    alert.setPositiveButton("Ok", newDialogInterface.OnClickListener() {
        @OverridepublicvoidonClick(DialogInterface dialog, int which) {
            editText.setFocusable(false);
        }
    });

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

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

Post a Comment for "Remove Focus From All Edit Text After Click On Ok From Alert Dialog"