Android学习记录(五) 记录一下最近遇到的坑:android actionbar menu菜单无显示。

本文提供了一种解决方案来确保应用程序的ActionBar中始终显示菜单图标。通过在onCreate()方法内使用ViewConfiguration类及其反射机制,可以禁用永久菜单键,从而使得溢出菜单图标始终出现在屏幕右上角。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里搬运一下:

http://stackoverflow.com/questions/18010072/menu-items-are-not-showing-on-action-bar

I think you want to show the overflow menu icon on the top right always and want your menu to open from there. Try something like following to force it there:

Inside your onCreate() do:

  try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if(menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

建议整篇读一下,非常不错~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值