Android-Android获取屏幕大小为什么会自动减去状态栏高度
1个回答
展开全部
public int getDisplayScreenHeight()
{
int screenHeight = 0;
DisplayMetrics metrics = new DisplayMetrics();
Display display = getWindowManager().getDefaultDisplay();
display.getMetrics(metrics);
int ver = Build.VERSION.SDK_INT;
if (ver < 13)
{
screenHeight = metrics.heightPixels;
}
else if (ver == 13)
{
try {
Method method = display.getClass().getMethod("getRealHeight");
screenHeight = (Integer) method.invoke(display);
} catch (Exception e) {
e.printStackTrace();
}
}
else if (ver > 13)
{
try {
Method method = display.getClass().getMethod("getRawHeight");
screenHeight = (Integer) method.invoke(display);
} catch (Exception e) {
e.printStackTrace();
}
}
return screenHeight;
}
{
int screenHeight = 0;
DisplayMetrics metrics = new DisplayMetrics();
Display display = getWindowManager().getDefaultDisplay();
display.getMetrics(metrics);
int ver = Build.VERSION.SDK_INT;
if (ver < 13)
{
screenHeight = metrics.heightPixels;
}
else if (ver == 13)
{
try {
Method method = display.getClass().getMethod("getRealHeight");
screenHeight = (Integer) method.invoke(display);
} catch (Exception e) {
e.printStackTrace();
}
}
else if (ver > 13)
{
try {
Method method = display.getClass().getMethod("getRawHeight");
screenHeight = (Integer) method.invoke(display);
} catch (Exception e) {
e.printStackTrace();
}
}
return screenHeight;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询