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条回答
太酷不给撩
2楼-- · 2019-01-13 05:50
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);

or

set activity property in manifest file as below in the application tag

android:windowSoftInputMode="stateHidden"
查看更多
爷、活的狠高调
3楼-- · 2019-01-13 05:50

Have another view grab focus. By default, the first focusable View will get focus when a layout is inflated. You can request focus on a different View via XML:

<TextView
    android:layout_width="wrap_parent"
    android:layout_height="wrap_content"
    android:text="Some other view">

    <requestFocus />
</TextView>

This works for any View.

If you want to do it programmatically, you can use view.requestFocus().

查看更多
登录 后发表回答