如何以编程方式识别bezel less android手机?

时间:2018-01-24 10:22:49

标签: android android-layout

如何识别无边框Android智能手机?在我的应用程序中,我有一个底部菜单,在bazel less智能手机中不可见。有人可以指导我吗?

2 个答案:

答案 0 :(得分:0)

通过此代码检查屏幕分辨率,

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int widthContentView = displaymetrics.widthPixels;
int heightContentView = displaymetrics.heightPixels;

如果高度和宽度的比例是18:9或2:1,那么它应该是一个没有bazel的设备。

答案 1 :(得分:0)

@jitendra purohit的回答是正确的。在这里,我已经改进了他获得比率的答案:

        DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int widthContentView = displaymetrics.widthPixels;
        int heightContentView = displaymetrics.heightPixels;
        heightContentView = heightContentView + getNavigationBarHeight();

        if(heightContentView/widthContentView == 2){
            Log.v("Bazel less Device","Bazel less");
        //if the ratio of height and width is 18:9 or 2:1 than it should be a bazel less device.
        }




    private int getNavigationBarHeight() {
        Resources resources = getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            return resources.getDimensionPixelSize(resourceId);
        }
        return 0;
    }