Android 3.0 中是否有在操作栏项目之间添加分隔线的标准方法?
我在尝试自定义应用程序中操作栏的外观时遇到了一个小问题。我希望能够使用像素宽的分隔线来对您在许多本机应用程序(例如 Gmail、日历)中看到的操作栏项目进行分组。我找到了一种方法来做到这一点,通过添加一个菜单项并将“android:actionLayout”属性设置为分隔线的自定义布局:
<View
android:background="@color/LightGray"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_width="1dip"
android:layout_height="fill_parent" />
这很好用,但问题是它算作一个菜单项,而操作栏似乎限制了菜单项的数量为 4 - 任何其他项都会被推入溢出菜单。
所以我想我要问的是是否有一种标准方法可以添加项目分隔符,而无需使用具有自定义视图的菜单项,并且以一种不计入操作栏项目限制的方式?
提前致谢!
I have a slight problem trying to customise the look of the action bar in my app. I want to be able to have the pixel wide dividers to group action bar items that you see in many of the native apps (e.g. Gmail, Calendar). I found a way to do this by adding a menu item and setting the 'android:actionLayout' attribute to a custom layout for the divider:
<View
android:background="@color/LightGray"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_width="1dip"
android:layout_height="fill_parent" />
This works nicely, but the issue is it counts as a menu item and the action bar seems to limit the number of menu items to 4 - any others get pushed into the overflow menu.
So I guess what I'm asking is whether there is a standard way to add item dividers without having to use a menu item with a custom view, and in a way that doesn't count towards the limit for action bar items?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不会尝试将分隔线强制放置到系统不会自动添加它们的位置,因为这会使您的应用程序与平台不一致。默认行为是:
I wouldn't try and force dividers into places that the system does not add them automatically as it will make your app inconsistent with the platform. The default behavior is:
我找不到标准方法,但我的方法是使用菜单项的 android:actionLayout 属性,然后将分隔线放在那里。
I couldn't find a standard way, but the way I did it was to use the
android:actionLayout
property for the menu item, and I put the divider in there.当 Google 发布 3.0 SDK 时,我得到了一个快速演示应用程序来查看 ActionBar 的工作原理,然后回顾一下它,如果我使用没有图标可绘制的文本项,那么我会绘制自动分隔线。
我的 menu.xml 文件是这样的:
也许这不适用于图标?
或者想想,也许图标的大小有影响?
When Google released the 3.0 SDK I got a quick demo app to see how the ActionBar works and just looking back at it, if I use Text Items without Icon drawables, then I get automatic dividers drawn.
My menu.xml file is like this:
Maybe this won't work with icons??
Or thinking about it, maybe the size of the icon has an effect?