Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SearchView gains focus and opens keyboard when returning from another activity

When I return from another activity to the main activity, the searchView gains focus and the keyboard opens, I managed to stop the keyboard from opening by using:

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

but this is not sufficient, if the actionbar drop down menu is opened and closed the keyboard reappears, because the searchView still has focus (remember I only closed the keyboard). I have tried to get a reference to the searchView and make it lose focus, but this has not worked.

So basically, I just want the searchView to never have focus or prompt the keyboard to open, unless the searchView text area is actually touched.

like image 966
timeshift117 Avatar asked Feb 07 '14 09:02

timeshift117


1 Answers

Leveraging on Adam S' answer, if you don't have any earlier View in the hierarchy before the SearchView, you could always include a dummy View like so:

<View
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:focusableInTouchMode="true"/>

<android.support.v7.widget.SearchView
    android:iconifiedByDefault="false"
    ... />

This also worked for me!

like image 188
Muhammad Faheem Mohd Ezani Avatar answered Sep 29 '22 12:09

Muhammad Faheem Mohd Ezani