Currently, I have a layout which contains a Button
, a TextView
and an EditText
. When the layout is displayed, the focus will be automa
You should add this:
android:focusableInTouchMode="true"
Try
comp.requestFocusInWindow();
None of the answers above works for me. The only (let's say) solution has been to change the first TextView in a disabled EditText that receives focus and then add
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
in the onCreate callback to prevent keyboard to be shown. Now my first EditText looks like a TextView but can get the initial focus, finally.
Set these lines to OnResume
as well and make sure if focusableInTouch
is set to true while you initialize your controls
<controlName>.requestFocus();
<controlName>.requestFocusFromTouch();
You can try just hidding the keyboard. Something like this:
InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
to change the focus make the textView in xml focusable
<TextView
**android:focusable="true"**
android:id="@+id/tv_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
and in java in on create
textView.requestFocus();
or simply hide the keyboard
public void hideKeyBoard(Activity act) {
act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
InputMethodManager imm = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
}