Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android hasPermanentMenuKey()不';行不通_Android - Fatal编程技术网

Android hasPermanentMenuKey()不';行不通

Android hasPermanentMenuKey()不';行不通,android,Android,我正在使用: if(ViewConfiguration.get(getActivity()).hasPermanentMenuKey()){ // whatever } 情况是,在带有Android Studio的模拟器中,它在任何API上都能完美运行,即使是25。但是在屏幕上没有导航条的手机上,比如三星,就不起作用了。如果Nexus 5检测到API 23,则在其上安装。解决方案: public boolean hasNavBar (Resources resource

我正在使用:

if(ViewConfiguration.get(getActivity()).hasPermanentMenuKey()){
        // whatever
    }
情况是,在带有Android Studio的模拟器中,它在任何API上都能完美运行,即使是25。但是在屏幕上没有导航条的手机上,比如三星,就不起作用了。如果Nexus 5检测到API 23,则在其上安装。

解决方案:

public boolean hasNavBar (Resources resources)
{
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    return id > 0 && resources.getBoolean(id);
}

如果问题解决了,为什么不干脆删除这个问题?@azizbekian:最好将答案移到答案框中,并自我接受,这样将来的读者可能会从中受益。我尝试你的解决方案。它很好用。ViewConfiguration.get(getActivity()).hasPermanentMenuKey()不适用于我的华硕Zenphone 4。调试并查看,它缺少什么?
public static boolean hasPermanentKeys(Activity activity) {
    //
    int height=0;
    int realHeight=0;

    WindowManager w = activity.getWindowManager();
    Display d = w.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    d.getMetrics(metrics);
    // since SDK_INT = 1;
     height = metrics.heightPixels;

// includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17)
        try {
            realHeight = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
        } catch (Exception ignored) {
        }
// includes window decorations (statusbar bar/menu bar)
    if (Build.VERSION.SDK_INT >= 17)
        try {
            Point realSize = new Point();
            Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize);
            realHeight = realSize.y;
        } catch (Exception ignored) {
        }
    if(height == realHeight){
        return true;
    }
    else{
        return false;
    }
}
 private int getNavigationBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}

if (!havingNavigation) {//there's a navigation bar
        bottomPadding += getNavigationBarHeight();
    }