问题
This question is a follow up to Show android SearchView EditText by default. My SearchView used to work fine until I added android:iconifiedByDefault="false"
to the layout. Now, when I click on the icon or type in the search field, no search takes place. Does anyone know how to fix this problem? here is my SearchView as it exists now.
<SearchView
android:id="@+id/search"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:queryHint="@string/search_hint"
android:iconifiedByDefault="false"
android:textSize="16sp" />
I already tried the following:
mSearch.setOnSearchClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onSearchRequested();
//other stuff happen here
}
});
回答1:
I solved the problem with
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) { ...}
}
回答2:
i solve this problem by simply adding requestFocus tag in SearchView widget.
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search"
android:clickable="true"
android:queryHint="Enter Song name.."
android:iconifiedByDefault="false">
<requestFocus/>
</SearchView>
来源:https://stackoverflow.com/questions/20981613/setting-iconified-to-false-on-android-searchview-cause-view-to-not-be-searchable