Android 4.3: Not Focus Searchview Not Show Hint
Android Studio 2.3.3, Android 4.3. In my fragment I has searchView component (not in ToolBar). Here my snippet. fragment_layout.xml: &l
Solution 1:
I found solution for Android 4.3+:
I use microphone icon , disable click on it and replace it by custom icon(glass)
Hide keyboard after 300 msec (because
onActionViewExpanded()
show soft keyboard)
As result I has:
- Show hint when searchView is not focus
- Show icon on the right side when searchView is on focus and when searchView is NOT in focus
Here my snippet:
Java code:
ImageViewvoiceButtonIcon= view.findViewById(android.support.v7.appcompat.R.id.search_voice_btn);
voiceButtonIcon.setImageResource(R.drawable.ic_search_black);
voiceButtonIcon.setEnabled(false);
// Workaround! Show hint when searchView has no focus
searchView.onActionViewExpanded();
newHandler().postDelayed(newRunnable() {
@Overridepublicvoidrun() {
searchView.clearFocus();
}
}, 300);
layout xml:
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/search_view_bg"
android:theme="@style/SearchViewTheme"
app:defaultQueryHint="@string/settings"
app:searchHintIcon="@null" />
As result: searchView has NO focus:
and searchView HAS in focus:
So hint show always!
Post a Comment for "Android 4.3: Not Focus Searchview Not Show Hint"