我的活动中有一个使用此代码的菜单:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:title="Search"
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView" />
还有一个oncreatoptionsmenu:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
Toast.makeText(getApplicationContext(),"onClose",Toast.LENGTH_LONG).show();
show_all_drugs();
return false;
}
});
return true;
}
但是近距离听众没有工作。什么问题?如何在活动的oncreate中使用我的搜索视图?
答案 0 :(得分:0)
试试这个:
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
Toast.makeText(getApplicationContext(),"hello",Toast.LENGTH_LONG).show();
show_all_drugs();
return true;
}