Unable to show keyboard automatically in the SearchView

Viewed 24422

The SearchView is focused by default, but when I try to show software keyboard - it doesn't happen:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

But when I click on the SearchView - it does. Why?

9 Answers

Best and simplest way to do it :

        android:focusable="true"
        app:iconifiedByDefault="false"
        android:focusableInTouchMode="true"

Add above three lines into your xml under SearchView and see the magic....!!

 <EditText
        android:id="@+id/edt_search"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:background="@null"
        android:ellipsize="end"
        android:hint="@string/SERACH"
        android:imeOptions="actionSearch"
        android:inputType="textVisiblePassword"
        android:singleLine="true"
        android:textAlignment="viewStart" />

add <requestFocus /> in your search view like this

<EditText
            android:id="@+id/et_search"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@android:color/transparent"
            android:imeOptions="actionSearch"
            android:maxLines="1"
            android:padding="8dp"
            android:singleLine="true"
            android:textAppearance="@style/TextAppearance.AppCompat.Large"
            android:textColor="@android:color/white"
            android:textColorHint="#e6e6e6">

            <requestFocus />

        </EditText>
Related