How to set focus on a view when a layout is created and displayed? How to set focus on a view when a layout is created and displayed? android android

How to set focus on a view when a layout is created and displayed?


Set focus: The framework will handled moving focus in response to user input. To force focus to a specific view, call requestFocus()


This works:

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


You should add this:

android:focusableInTouchMode="true"