android 修改菜单大小,Android:更改溢出菜单的宽度

我正在阅读[

http://keepsafe.github.io/2014/11/19/building-a-custom-overflow-menu.html]教程,但没有提到改变宽度的方法

所以我也在寻找相同的答案并一直在寻找,Stackoverflow上的所有问题都没有答案.最后,我不得不挖掘developer.google.com以找到方法.

你会发现一个实际完成我们工作的方法setContentWidth(int width).

这是答案

//.......... Something on top

popupMenu.show();

// Try to force some horizontal offset

try {

Field fListPopup = menuHelper.getClass().getDeclaredField("mPopup");

fListPopup.setAccessible(true);

Object listPopup = fListPopup.get(menuHelper);

argTypes = new Class[] { int.class };

Class listPopupClass = listPopup.getClass();

// Get the width of the popup window

int width = (Integer) listPopupClass.getDeclaredMethod("getWidth").invoke(listPopup);

// Invoke setHorizontalOffset() with the negative width to move left by that distance

listPopupClass.getDeclaredMethod("setHorizontalOffset", argTypes).invoke(listPopup, -width);

/*********** THIS LINE DOSE OUR WORK and increases the width of OverFlow Menu ******/

listPopupClass.getDeclaredMethod("setContentWidth", argTypes).invoke(listPopup, width+200);

// Invoke show() to update the window's position

listPopupClass.getDeclaredMethod("show").invoke(listPopup);

} catch (Exception e) {

// Again, an exception here indicates a programming error rather than an exceptional condition

// at runtime

Log.w("Soemthing", "Unable to force offset", e);

}

fa3533f4be0404be7f63f71bdbab326e.png

对此==>

033a483528a2232608966510a9f43f97.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值