简体   繁体   English

长按菜单可在操作栏中打开其他SearchView小部件

[英]Menu long-click opens different SearchView widget in action bar

I have a search icon in my Activity 's action bar and when I click it it opens a default Android SearchView widget in my action bar. 我的“ Activity ”操作栏中有一个搜索图标,当我单击它时,它会在我的操作栏中打开一个默认的Android SearchView小部件。 However, if I long-click capacitive menu button on my Samsung Galaxy S3 device it opens a different SearchView widget that doesn't even match with my app's action bar. 但是,如果我在Samsung Galaxy S3设备上长按电容菜单按钮,它将打开另一个与我的应用程序的操作栏不匹配的SearchView小部件。 Furthermore, with menu long-click I can open the SearchView widget in my searchable Activity that doesn't even have the search icon in the action bar and isn't the desired Activity to support the SearchView widget in the action bar, it is just for handling the search Intent . 此外,通过长按菜单,我可以在searchable Activity中打开SearchView小部件,该searchable Activity甚至在操作栏中没有搜索图标,也不是在操作栏中支持SearchView小部件的理想Activity用于处理搜索Intent I'll post some screenshots for you to better understand my problem... 我将发布一些屏幕截图供您更好地了解我的问题...

My MainActivity with search icon: 我的带有搜索图标的MainActivity 我的带有搜索图标的<code> MainActivity </ code> My MainActivity with SearchView widget expanded via search icon press: 我的带有SearchView小部件的MainActivity通过按搜索图标展开: 我的<code> MainActivity </ code>和<code> SearchView </ code>小部件通过按搜索图标展开 My MainActivity after menu long-click (completely different SearchView widget style): 菜单长按后我的MainActivity (完全不同的SearchView小部件样式): 菜单长按后,我的<code> MainActivity </ code> My searchable Activity (doesn't contain search icon and shouldn't provide search): 我的searchable Activity (不包含搜索图标,也不应该提供搜索): 我的<code>可搜索活动</ code> My searchable Activity after menu long-click ( SearchView widget shouldn't exist here...): 菜单长按后我的searchable ActivitySearchView小部件在这里不应该存在...): 菜单长按后我的<code>可搜索活动</ code> So I am asking you to help me to find out: 因此,我想请您帮助我找出答案:

  1. Why menu long-click action opens completely different SearchView widget? 为什么菜单长按操作会打开完全不同的SearchView小部件?
  2. Why is it possible to open that SearchView widget in the searchable Activity that shouldn't support search functionality but just handle the search Intent sent from my MainActivity which should be the only Activity that contains the search icon and search functionality? 为什么可以在不支持搜索功能的searchable Activity中打开SearchView小部件,而只处理从我的MainActivity发送的搜索Intent ,它应该是唯一包含搜索图标和搜索功能的Activity
  3. How to achieve that menu long-click opens the same SearchView widget as the search icon in the action bar and only in the MainActivity ? 如何长按菜单以打开与操作栏中的搜索图标相同的SearchView小部件,并且仅在MainActivity中打开?
  4. If 3 isn't possible then how to completely disable the menu long-click actions? 如果不可能3,那么如何完全禁用菜单长按操作?

Here's the answer for 4th question. 这是第四个问题的答案。 Add this function in your activity class. 在活动类中添加此函数。

@Override
public boolean onSearchRequested() {
    return false;
}

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

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