android 始终显示overflow菜单
一般的來(lái)說(shuō)在Actionbar中在條目過(guò)多時(shí)會(huì)顯示三個(gè)豎著的小點(diǎn)的菜單,但在實(shí)機(jī)測(cè)試的時(shí)候發(fā)現(xiàn)并不顯示,上網(wǎng)查找了之后發(fā)現(xiàn)問(wèn)題所在:如果該機(jī)器擁有實(shí)體的menu鍵則不在右側(cè)顯示溢出菜單,而改為按menu來(lái)生成。這樣就不利于統(tǒng)一的界面風(fēng)格。
我們可以改變系統(tǒng)探測(cè)實(shí)體menu鍵的存在與否來(lái)改變這個(gè)的顯示。
菜單顯示是根據(jù)public boolean hasPermanentMenuKey ()這個(gè)方法來(lái)判斷的。這個(gè)方法是獲取sHasPermanentMenuKey的boolean值。
解決辦法:通過(guò)在onCreate()中
try {
ViewConfiguration mconfig = ViewConfiguration.get(this);
? ? ? ?Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
? ? ? ?if(menuKeyField != null) {
? ? ? ? ? ?menuKeyField.setAccessible(true);
? ? ? ? ? ?menuKeyField.setBoolean(mconfig, false);
? ? ? ?}
? ?} catch (Exception ex) {
? ?}
轉(zhuǎn)載于:https://my.oschina.net/liangzhenghui/blog/198455
總結(jié)
以上是生活随笔為你收集整理的android 始终显示overflow菜单的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: android设置提交的隐藏域以及在on
- 下一篇: 子页面刷新父页面,避免弹出重复提交窗口