---
title: "Android获得屏幕高度和状态栏高度"
author: "mmdev"
date: "2012-12-03T10:35:00Z"
tags: []
slug: "android"
draft: false
lastmod: "2012-12-05T22:11:50Z"
id: 1742193
url: "https://mmdev.iteye.com/blog/1742193"
---

在onCreate()中无法获得，必须在下面的方法中：

@Override

publicvoidonWindowFocusChanged(booleanhasFocus){

//TODOAuto-generatedmethodstub

super.onWindowFocusChanged(hasFocus);

getWindow().findViewById(Window.ID\_ANDROID\_CONTENT);

Displaydisplay=getWindowManager().getDefaultDisplay();

//屏幕高度

intheight=display.getHeight();

Rectframe=newRect();

getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

//状态栏高度

intstatusBarHeight=frame.top;

}