学习《第一行代码》使用实机测试所遇问题(二)

实机使用酷派大神F1,添加menu后,右上角不出现菜单,此时在java代码中加入以下方法在onCreate中运行

private void makeActionOverflowMenuShown() {
//devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu
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) {

}
}


加入此代码后,再测试即可出现菜单选项
posted @ 2017-05-04 23:05  怨灵骑士  阅读(327)  评论(0编辑  收藏  举报