美文网首页
Android NavigationBar是否显示 三星华为 亲

Android NavigationBar是否显示 三星华为 亲

作者: yun_265f | 来源:发表于2019-01-15 18:06 被阅读0次

```java

/**

* 获取是否存在NavigationBar

*

* @param activity

* @return

*/

public static boolean checkDeviceHasNavigationBar(Activity activity) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

Display display = activity.getWindowManager().getDefaultDisplay();

        Point size =new Point();

        Point realSize =new Point();

        display.getSize(size);

        display.getRealSize(realSize);

        return realSize.y != size.y;

    }else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

// navigation bar was introduced in Android 4.0 (API level 14)

        Resources resources = activity.getResources();

        int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");

        if (id >0) {

return resources.getBoolean(id);

        }else {// Check for keys

            boolean hasMenuKey = ViewConfiguration.get(activity).hasPermanentMenuKey();

            boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

            return !hasMenuKey && !hasBackKey;

        }

}else {

return false;

    }

}

```

相关文章

网友评论

      本文标题:Android NavigationBar是否显示 三星华为 亲

      本文链接:https://www.haomeiwen.com/subject/aeaydqtx.html