Close/Hide the input keyboard autofocus on Activity start

Using layout xml file

Setting android:focusable attribute to false removes the auto focus of EditText or AutoCompleteTextView.

android:focusable="false"

Example

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Name"

android:textSize="18dp"

android:focusable="false"

android:textStyle="italic"/>

<AutoCompleteTextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Search"

android:textSize="18dp"

android:focusable="false"

/>

Using dummy LinearLayout in layout xml file

Setting android:focusableInTouchMode attribute to true in LinearLayout removes the auto focus of EditText or AutoCompleteTextView.

android:focusableInTouchMode="true"

Example

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:focusable="true"

android:focusableInTouchMode="true"/>

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Name"

android:textSize="18dp"

android:focusable="false"

android:textStyle="italic"/>

Programatically in Java

if(getCurrentFocus()!=null) {

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

}