美文网首页
获取全面屏高度

获取全面屏高度

作者: 安宇辛 | 来源:发表于2020-09-18 11:41 被阅读0次

亲测可用

public int getScreentHeight() {

int heightPixels;

        WindowManager w =this.getWindowManager();

        Display d = w.getDefaultDisplay();

        DisplayMetrics metrics =new DisplayMetrics();

        d.getMetrics(metrics);

        // since SDK_INT = 1;

        heightPixels = metrics.heightPixels;

        // includes window decorations (statusbar bar/navigation bar)

        if (Build.VERSION.SDK_INT >=14 && Build.VERSION.SDK_INT <17)

try {

heightPixels = (Integer) Display.class

                        .getMethod("getRawHeight").invoke(d);

            }catch (Exception ignored) {

}

// includes window decorations (statusbar bar/navigation bar)

        else if (Build.VERSION.SDK_INT >=17)

try {

android.graphics.Point realSize =new android.graphics.Point();

                Display.class.getMethod("getRealSize",

                        android.graphics.Point.class).invoke(d, realSize);

                heightPixels = realSize.y;

            }catch (Exception ignored) {

}

//        Log.e("realHightPixels-heightPixels", heightPixels + "width");

        return heightPixels;

    }

相关文章

网友评论

      本文标题:获取全面屏高度

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