Currently, I have a layout which contains a Button
, a TextView
and an EditText
. When the layout is displayed, the focus will be automatically put on the EditText
, which will trigger the keyboard to show up on Android phone. It is not what I want. Is there any way that I can set the focus on TextView
or on nothing when a layout is displayed?
If you are using java code to generate layout then you can use methods setFocusable(boolean) and setFocusableInTouchMode(boolean). You can then set the focus to a view using public method requestFocus(). The framework will handle routine focus movement in response to user input.
Focusable in touch mode is a property that you can set yourself either from code or XML. However, it should be used sparingly and only in very specific situations as it breaks consistency with Android normal behavior.
RequestFocus() Call this to try to give focus to a specific view or to one of its descendants.
This works:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Set focus: The framework will handled moving focus in response to user input. To force focus to a specific view, call requestFocus()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With