简体   繁体   English

Android,我想在动作栏中添加searchview但没有

[英]android i want to add searchview in actionbar but not got it

i have a layout in which on the title bar i have option button and back button which work fine now i want to add searchview in the action bar but i dont know how to do this i am new in android so please help me to solve my problem. 我在标题栏上有一个布局,在其中我有选项按钮和后退按钮,它们现在可以正常工作。我想在操作栏中添加searchview,但是我不知道该怎么做,我是android的新手,所以请帮助我解决我的问题问题。

this is my activity code. 这是我的活动代码。

    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() {

    }
}

this is manu res file 这是手册资源文件

<?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" />

this is string.xml file 这是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>

i have title bar like as 我有像这样的标题栏 在此处输入图片说明

查看Android Developer,它逐步显示了如何添加搜索功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM