本文介绍了动作条菜单项分频器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,以显示菜单项的动作条的蜂窝+之间的分隔。

Is there a way to show Divider between the Menu Items in ActionBar for HoneyComb+.

有些帖子说,该分频器将显示只有在菜单项目有机器人:showAsAction =withText

Some post says that the Divider will be shown only when the menu items has android:showAsAction="withText".

我想只显示图标而不是文本。

I want to show only the Icon not the Text.

我成功地分隔显示为pre-蜂窝通过实施行动吧兼容性。

I successfully shown Divider for Pre-HoneyComb by implementing a Action Bar Compatibility.

我不想使用ActionBarSherlock在这篇文章Android动作条sherlok不显示分,因为这将是一次从操作栏的兼容性,以改变我的所有项目ActionBarSherlock。

I dont want to use ActionBarSherlock as given in this post Android actionbar sherlok doesn't show divider because it will be time to change from Action Bar Compatibility to ActionBarSherlock in my all Projects.

当我看到了Android的源代码,我发现分频器将显示,只有当它有文字,如下图所示(从ActionMenuItemView)

When i saw the Android Source i found that Divider will be show only when it has text as shown below (from ActionMenuItemView)

public boolean needsDividerBefore() {
    return hasText() && mItemData.getIcon() == null;
}

public boolean needsDividerAfter() {
    return hasText();
}

有没有一种方法,我可以给我的执行情况ActionMenuItemView的动作条,其中needsDividerBefore()总会给真正的

Is there a way that I can give my Implementation for ActionMenuItemView for ActionBar where needsDividerBefore() will always give true

推荐答案

找到答案由提问者自己与http://android-developers.blogspot.in/2011/04/customizing-action-bar.html但是,这并彻底解决我的问题。它增加一个分标题也因此为家庭图标有左,右分隔符。那也是可调节的。

Found answer by myself with help of http://android-developers.blogspot.in/2011/04/customizing-action-bar.html But that does completely solve my problem. Its add a divider for Title also so for home Icon there are left and right seperator. That too is adjustable.

我添加的android:selectableItemBackground我的主题

i added android:selectableItemBackground to my theme.

<item name="android:selectableItemBackground">@drawable/action_bar_item_selector</item>

action_bar_item_selector.xml

action_bar_item_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/actionbar_compat_separator"></item>

    <item android:left="1dp" android:drawable="@drawable/actionbar_compat_item"></item>

</layer-list>

actionbar_compat_separator - 是我的分隔符绘制

actionbar_compat_separator - is my seperator drawable

和actionbar_compat_item是我选择的动作栏项目。

and actionbar_compat_item is my selector for action bar item.

EDITED

我的问题找到更好的解决办法,工作良好。

Found better solution to my problem, Work good.

<item name="android:actionButtonStyle">@style/ActionButton</item> to my Theme

<style name="ActionButton" parent="android:style/Widget.Holo.Light.ActionButton">
        <item name="android:background">@drawable/action_bar_item_selector</item>
    </style>

这篇关于动作条菜单项分频器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:51