单击SearchView中的搜索按钮,更改ActionBar样式(Clicking on search button from SearchView, changes ActionBar style)

编程入门 行业动态 更新时间:2024-10-19 03:27:59
单击SearchView中的搜索按钮,更改ActionBar样式(Clicking on search button from SearchView, changes ActionBar style)

我正在使用SearchView在应用程序中提供搜索。 一切正常,除非我在可搜索的活动中并点击搜索按钮。

这是打开SearchableActivity确定(ok):

如果我单击搜索按钮以启动新搜索(不正常),会发生这种情况:

正如您可以看到ActionBar的样式更改(操作栏和建议下拉列表),它看起来像启用操作模式时,我不知道为什么会发生这种情况。

现在我单击向后或向上按钮,ActionBar将重置为初始样式(单击搜索按钮时应该得到什么):

任何帮助表示赞赏。 谢谢。

I am using SearchView to provide search in an application. Everything works fine, except when I'm in the searchable activity and click on the search button.

This is when opening the SearchableActivity (ok):

This is what happens if I click on the search button to initiate a new search (not ok):

As you can see the style of the ActionBar changes (both action bar and suggestion dropdown), it looks like when the action mode is enabled, and I don't have idea why this is happening.

And now I click back or up button, the ActionBar is reset to initial style (what should I get when clicking on the search button):

Any help is appreciated. Thank you.

最满意答案

这个问题是因为在SearchableActivity我拦截了搜索按钮并调用了onSearchRequested() :

@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_search: onSearchRequested(); return true; default: return false; } }

没有必要覆盖onOptionsItemSelected() ,删除这段代码解决了这个问题。

The issue was caused because in the SearchableActivity I was intercepting the search button and calling onSearchRequested():

@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_search: onSearchRequested(); return true; default: return false; } }

There's no need for onOptionsItemSelected() to be overrided, deleteting this piece of code solved the issue.

更多推荐

本文发布于:2023-08-07 11:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464472.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   样式   按钮   SearchView   style

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!