Action Bar Icon hidden after SearchView expands

2019-03-24 14:55发布

When SearchView is collapsed

When SearchView expands

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".

2条回答
放荡不羁爱自由
2楼-- · 2019-03-24 15:11

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-24 15:36

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); 
查看更多
登录 后发表回答