我有一个布局,在标题栏上我有选项按钮和后退按钮,现在工作正常我想在操作栏中添加searchview但我不知道如何做到这一点我是新的android所以请帮助我解决我的问题。
这是我的活动代码。
public class Thrd extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_thrd);
getSupportActionBar().setTitle("3rd page");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#20a780"));
getSupportActionBar().setBackgroundDrawable(colorDrawable);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_Exit:
openExit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void openExit() {
}
}
这是manu res文件
<?xml version="1.0" encoding="utf-8"?>
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_Exit"
android:title="@string/action_Exit"
android:showAsAction="never" />
这是string.xml文件
<resources>
<string name="app_name">QDAS</string>
<string name="hello_world">Hello world!</string>
<string name="action_Exit">Exit</string>
<string name="title_activity_secnd">Secnd</string>
<string name="title_activity_thrd">Thrd</string>
<string name="action_settings">Settings</string>
我有像标题栏一样的标题栏