How to remove auto focus/keyboard popup of a field

2019-01-13 04:55发布

I have a screen where the first field is an EditText, and it gains the focus at startup, also popups the numeric input type, which is very annoying

How can I make sure that when the activity is started the focus is not gained, and/or the input panel is not raised?

8条回答
ゆ 、 Hurt°
2楼-- · 2019-01-13 05:28

go to your application manifest file, and write this line for that activity you want to disable auto keyboard pop-up.

android:windowSoftInputMode="stateHidden"
查看更多
孤傲高冷的网名
3楼-- · 2019-01-13 05:28

This is usually a mess. The first thing I try is try to steal the focus with another view via . You also have to have the focusable and focusableInTouchMode.

<TextView
  ...
  android:focusable="true"
  android:focusableInTouchMode="true">

    <requestFocus/>
</TextView>
查看更多
虎瘦雄心在
4楼-- · 2019-01-13 05:38
if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED)
{
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
查看更多
贼婆χ
5楼-- · 2019-01-13 05:41

have not tried this nor am i near my programming computer, but I would suspect programmatically sending focus to the parent view or something of that nature could do the trick - thats more likely a workaround than a solution, but again not able to test it just a thought

查看更多
我只想做你的唯一
6楼-- · 2019-01-13 05:46

To programatically not have the keyboard displayed, but the default widget still recieve focus call:

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

in onResume()

查看更多
【Aperson】
7楼-- · 2019-01-13 05:48
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

call the above method inside onCreate().It prevent softKeyboard to show unless user select EditText by tapping or clicking.

or simply add android:windowSoftInputMode="stateHidden" in Activity tag in Manifest.xml

查看更多
登录 后发表回答