简体   繁体   English

拥有导航抽屉时在操作栏中显示菜单项图标

[英]Show menu item icons in actionbar while having navigation drawer

Been trying everything to show the menu item search (searchWidget) in the actionbar. 一直试图在操作栏中显示菜单项搜索(searchWidget)。 I have a navigationdrawer, which doesn't hide the actionbar items at any time. 我有一个NavigationDrawer,它不会随时隐藏操作栏项。 But still the search item is always at the overflow, even when having a large screen device. 但是,即使具有大屏幕设备,搜索项仍然总是溢出。

I have tried using always in the showAsAction in the menu item, and even putting the menu item as visible in the onPrepareOptionsMenu method, and calling it when the drawer opens and closes to see if something changed, and still nothing. 我试过始终在菜单项的showAsAction中使用它,甚至将该菜单项放在onPrepareOptionsMenu方法中可见,并在抽屉打开和关闭时调用它,以查看是否有所更改,但仍然没有。

I won't post code now, just wondering if someone had the same problem. 我现在不会发布代码,只是想知道是否有人遇到相同的问题。 If necessary I will post code of course. 如有必要,我当然会发布代码。

If you are using regular action bar menu items (API 13+) then you simply need to say - 如果您使用的是常规操作栏菜单项(API 13+),则只需说-

android:showAsAction="always"

for that menu item in the menu resource. 菜单资源中该菜单项。

However, if you are using the compat library - appcompat-v7 for action bar and menu items (API 7+) then you need your app's name as the namespace as - 但是,如果您使用compat库-用于操作栏和菜单项的appcompat-v7(API 7+),则需要将应用程序的名称作为名称空间,例如-

yourapp:showAsAction="always"

and add the following to menu tag at the top with the android namespace as - 并将以下内容添加到顶部的菜单标签中,其中android名称空间为-

xmlns:yourapp="http://schemas.android.com/apk/res-auto"

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

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