您好我正在尝试在工具栏中显示SearchView
。如果我使用自定义布局而不是app:actionViewClass="android.support.v7.widget.SearchView
,则会显示。请找到以下代码。
menu_search_page.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MyActivity" >
<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"/>
活动
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_page_layout);
activity = this;
toolbar = (Toolbar) findViewById(R.id.tool_bar);
toolbar.setLogo(R.drawable.new_logo);
toolbar.setTitle("");
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu_search_page, menu);
return super.onCreateOptionsMenu(menu);
}