Android: Force EditText to remove focus? [duplicate] Android: Force EditText to remove focus? [duplicate] android android

Android: Force EditText to remove focus? [duplicate]


You can make cursor and focus disappear by

edittext.clearFocus();

But detect when the key board hide is a hard work.


You can add this to onCreate and it will hide the keyboard every time the Activity starts.

You can also programmatically change the focus to another item.

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


Add LinearLayout before EditText in your XML.

<LinearLayout     android:focusable="true"    android:focusableInTouchMode="true"     android:clickable="true"    android:layout_width="0px"    android:layout_height="0px" />

Or you can do this same thing by adding these lines to view before your 'EditText'.

<Button    android:id="@+id/btnSearch"    android:layout_width="50dp"    android:layout_height="50dp"    android:focusable="true"    android:focusableInTouchMode="true"    android:gravity="center"    android:text="Quick Search"    android:textColor="#fff"    android:textSize="13sp"    android:textStyle="bold" /><EditText    android:id="@+id/edtSearch"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_alignParentLeft="true"    android:layout_centerVertical="true"    android:layout_marginRight="5dp"    android:gravity="left"    android:hint="Name"    android:maxLines="1"    android:singleLine="true"    android:textColorHint="@color/blue"    android:textSize="13sp"    android:textStyle="bold" />