android xmenu 点击,菜单项未显示在操作栏上[重复] - Menu items doesn't show up on the actionbar [duplicate] - 开发者知识库...

5

Okay I think I found a solution for you. It is called Overflow Menu and you need to call the below method in your onCreate method.

好吧,我想我找到了适合你的解决方案。它被称为溢出菜单,您需要在onCreate方法中调用以下方法。

private void getOverflowMenu() {

try {

ViewConfiguration config = ViewConfiguration.get(this);

Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");

if(menuKeyField != null) {

menuKeyField.setAccessible(true);

menuKeyField.setBoolean(config, false);

}

} catch (Exception e) {

e.printStackTrace();

}

}

Try this and let me know if it works for you.

试试这个,让我知道它是否适合你。

EDIT:

编辑:

I think I understood your problem finally. I can give you one idea. If you do not want to use overflow menu and just display menu items as displayed in the screen-shot you have posted, you can create a layout on top of your activity.

我想我终于理解了你的问题。我可以给你一个想法。如果您不想使用溢出菜单并只显示已发布的屏幕截图中显示的菜单项,则可以在活动之上创建布局。

You can take a linear layout, give a background that looks the same as action bar and place whatever icons you want to put there, and give functionality to them with onClickListener. Hope this will give you some idea. This way you can create your own custom menu. Try the layout below and replace ic_launcher drawable with menu icons. Then just set onClickListeners to them and perform whatever functions you want to perform inside onClick method.

您可以采用线性布局,提供与操作栏看起来相同的背景,并放置您想要放置的任何图标,并使用onClickListener为它们提供功能。希望这会给你一些想法。这样您就可以创建自己的自定义菜单。尝试下面的布局,并用菜单图标替换ic_launcher drawable。然后只需将onClickListeners设置为它们,并执行要在onClick方法中执行的任何函数。

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:background="#66000000" >

android:id="@+id/xMenuBtn1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:background="@drawable/ic_launcher" />

android:id="@+id/xMenuTxt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Chats"

android:textSize="18sp"

android:layout_toRightOf="@+id/xMenuBtn1"

android:layout_centerVertical="true" />

android:id="@+id/xMenuBtn2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toLeftOf="@+id/xMenuBtn3"

android:background="@drawable/ic_launcher" />

android:id="@+id/xMenuBtn3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:background="@drawable/ic_launcher" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值