1

I have an edit text which is placed as the first widget in my screen. So every time the page load the cursor stands inside this edit text, which I don't require. How can I remove focus from this when the page gets loaded? I tried with edittext.clearFocus(), but it didn't work out. Can anyone please reply me a solution? Thanks in advance.

Anju
  • 8,924
  • 14
  • 50
  • 86

2 Answers2

2
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

This can be used to suppress the keyboard until the user actually touched the edittext view.

From Close/hide the Android Soft Keyboard:

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field.

InputMethodManager imm =
    (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.HIDE_IMPLICIT_ONLY as the second parameter to ensure you only hide the keyboard when the user didn't explicitly force it to appear (by holding down menu).

Community
  • 1
  • 1
Waza_Be
  • 39,545
  • 47
  • 176
  • 256
0

You can have request focus in any other field, or this should not be the first field.