1. 程式人生 > >學習《第一行代碼》使用實機測試所遇問題(二)

學習《第一行代碼》使用實機測試所遇問題(二)

make 代碼 出現 onf msu field menus action java代碼

實機使用酷派大神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) {

}
}


加入此代碼後,再測試即可出現菜單選項

學習《第一行代碼》使用實機測試所遇問題(二)