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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With