How to stop EditText from gaining focus at Activity startup in Android

后端 未结 30 2712
别那么骄傲
别那么骄傲 2020-11-21 06:40

I have an Activity in Android, with two elements:

  1. EditText
  2. ListView

When my Activity

30条回答
  •  孤街浪徒
    2020-11-21 07:08

    Easiest way to hide keyboard is using setSoftInputMode

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

    or you can use InputMethodManager and hide keyboard like this.

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

提交回复
热议问题