问题
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