Action Bar Icon hidden after SearchView expands

落花浮王杯 提交于 2019-12-21 03:33:07

问题


I want the icon beside the SearchView (the "cloud") stays visible even when the SearchView expands. This works properly for tablets but doesn't work in case of smaller devices like Nexus 5.

I have set the showAsAction="always" for this menu item. Also, the SearchView has this attribute: showAsAction="ifRoom".


回答1:


try with this, works for me using appCompat v21

final MenuItem switchButton = menu.findItem(R.id.action_import);
final MenuItem searchItem = menu.findItem(R.id.action_search);

MenuItemCompat.setShowAsAction(searchItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
MenuItemCompat.setShowAsAction(switchButton, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); 



回答2:


What I have done for a situation like this is using a toolbar in xml while setting the theme to be NO_ACTION_BAR. Then in the toolbar (in my layout.xml file) I put a RelativeLayout. Using the leftOf=@id/someButton you should be able to keep all the buttons visible at all times.



来源:https://stackoverflow.com/questions/23380857/action-bar-icon-hidden-after-searchview-expands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!