为什么ActionbarSharelock只显示溢图标甚至有房 [英] Why ActionbarSharelock shows only overflow icon even there are room

查看:154
本文介绍了为什么ActionbarSharelock只显示溢图标甚至有房的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持菜单项可视性的ABS,甚至还有房间的头。事情是我有测试装置不同的大小,但在每种情况下,我能够只看到一个,那就是溢出菜单。

I am stuck with Menu item visibility in ABS even there are room in header. Thing is I have test in different size of device but in each case i am able to see only one and that is Overflow menu.

我使用在prepareOptionsMenu 为动态管理我的菜单和工作完全。(但不知道可能是这个问题出现轮空在prepareOptionsMenu 或其他原因)。

I am using onPrepareOptionsMenu to manage my menu as dynamically and that is working perfectly.(but don't know may be this issue is occur bye onPrepareOptionsMenu or some other reason).

查看差异:

View Difference:

第一种方法我已创建菜单编程和使用的 setShowAsAction()。某处我已经找到<一href="http://developer.android.com/reference/android/view/MenuItem.html#setShowAsActionFlags%28int%29"相对=nofollow> setShowAsActionflag()也和我有尝试之谓也。但是,在这种情况下,我不能够看到溢出菜单小屏幕320 * 480 。所以,这是编程的方法我的问题。

First Approach I have create menu programmatically and set that visibility using setShowAsAction(). Somewhere i have found setShowAsActionflag() also and i have try that also. But in that case i am not able to see Overflow menu in small screen 320*480. So, That is my issue in programmatically approach.

下面是我的code

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // TODO Auto-generated method stu
    // TO Remove older menu otherwise that will apped menu each time.
    menu.clear();

    menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, "Search").setIcon(R.drawable.ic_search).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(Menu.NONE, MENU_SETTING, Menu.NONE, "Settings").setIcon(R.drawable.ic_action_settings)
        .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    if (is_session_exist == 1) {
        menu.add(Menu.NONE, MENU_CHANGE_LOGIN, Menu.NONE, "Change Login").setIcon(R.drawable.ic_action_add_person)
            .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        menu.add(Menu.NONE, MENU_LOGOUT, Menu.NONE, "Logout").setIcon(R.drawable.abs__ic_clear)
            .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);


    } else {
        menu.add(Menu.NONE, MENU_LOGIN, Menu.NONE, "Login").setIcon(R.drawable.ic_action_add_person)
            .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    }
    return super.onPrepareOptionsMenu(menu);
}

第二种方法我在使用XML文件夹,并设置所有属性在不同的文件中创建菜单。现在我活用在prepareOptionsMenu在的菜单但在这种情况下,我只能看到任何密度显示屏溢图标,即使我已经设置了安卓:showAsAction =ifRoom | withText

Second Approach I have create menu using XML folder and set all property in separate file. Now i am inflecting that menu in onPrepareOptionsMenu but in that case i am only able to see overflow icon in any density screen even i have set the android:showAsAction="ifRoom|withText"

下面是我的XML code。

Here is my XML code.

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

    <item
        android:id="@+id/mainMenu"
        android:icon="@drawable/abs__ic_menu_moreoverflow_holo_dark"
        android:showAsAction="always">
        <menu>
            <item
                android:id="@+id/menu_search"
                android:icon="@drawable/ic_search"
                android:showAsAction="ifRoom|withText"
                android:title="Search"
                android:visible="true"/>
            <item
                android:id="@+id/menu_login"
                android:icon="@drawable/ic_action_add_person"
                android:showAsAction="ifRoom|withText"
                android:title="Login"
                android:visible="true"/>
            <item
                android:id="@+id/menu_change_login"
                android:icon="@drawable/ic_action_add_person"
                android:showAsAction="ifRoom|withText"
                android:title="Change Login"
                android:visible="false"/>
            <item
                android:id="@+id/menu_setting"
                android:icon="@drawable/ic_action_settings"
                android:showAsAction="ifRoom|withText"
                android:title="Setting"
                android:visible="true"/>
            <item
                android:id="@+id/menu_logout"
                android:icon="@drawable/abs__ic_clear"
                android:showAsAction="ifRoom|withText"
                android:title="Logout"
                android:visible="false"/>
        </menu>
    </item>

</menu>

我改变菜单项在prepareOptionsMenu 使用的setVisible(假/真);

下面我所引用了,但是问题没有解决还没有一些有用的链接。

Here some helpful link which i have refer already but issue is not solve yet.

<一个href="http://stackoverflow.com/questions/15138305/set-androidshowasaction-ifroomwithtext-programmatically">Set机器人:showAsAction =&QUOT; ifRoom | withText&QUOT;编程

如何添加文本在动作条图标?

我不知道为什么我得到这个问题。你的帮助和努力肯定会AP preciate。

I don't know why i am getting this issue .Your help and effort will definitely appreciate.

感谢您。

推荐答案

我想,与屏幕分辨率设备320 * 480,你不会得到溢出图标上,而不是点击该设备的菜单按钮,你可以得到休息菜单项目如下图:

I guess, for devices with screen resolution 320*480 you wont get an overflow icon, instead on click of menu button of the device you can get the rest menu items as below image:

这篇关于为什么ActionbarSharelock只显示溢图标甚至有房的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆