【问题标题】:auto open searchin action bar only shows keyboard自动打开 searchin 操作栏只显示键盘
【发布时间】:2013-07-24 01:22:40
【问题描述】:

我试图在我的搜索页面启动时自动打开操作栏中的搜索栏。我用它来尝试在页面打开时自动打开搜索栏:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);

        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setIconified(false);
        searchView.setOnQueryTextListener(this);
        return true;
    }

问题是当页面打开时,键盘弹出但搜索栏没有展开,因此用户可以开始输入搜索。它看起来像这样:

【问题讨论】:

    标签: android android-actionbar android-search


    【解决方案1】:
    • 使用searchItem.expandActionView();

    • 在菜单文件中,使用showAsAction="ifRoom|collapseActionView"

      如有任何疑问,请随时发表评论。

    【讨论】:

      【解决方案2】:

      可以使用setIconifiedByDefault(false)表示默认设置

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-11
        • 1970-01-01
        相关资源
        最近更新 更多