【问题标题】:android i want to add searchview in actionbar but not got itandroid 我想在操作栏中添加搜索视图但没有得到它
【发布时间】:2015-07-05 16:11:59
【问题描述】:

我有一个布局,其中在标题栏上我有选项按钮和后退按钮现在可以正常工作我想在操作栏中添加搜索视图但我不知道如何做到这一点我是 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() {

    }
}

这是手动文件

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

我有像这样的标题栏

【问题讨论】:

    标签: android android-actionbar searchview


    【解决方案1】:

    看看Android Developer,它一步一步地展示了如何添加搜索功能。

    【讨论】:

      猜你喜欢
      • 2016-11-05
      • 2016-04-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多