---
title: "【实用】获取Android状态栏的方法"
author: "810364804"
date: "2014-09-17T00:36:00Z"
tags: []
slug: "android"
draft: false
lastmod: "2014-09-17T11:22:42Z"
id: 2117289
url: "https://810364804.iteye.com/blog/2117289"
---

```
private static int getStatusHeight(Context context){
        int statusHeight = 0;
        Rect localRect = new Rect();
        ((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
        statusHeight = localRect.top;
        if (0 == statusHeight){
            Class<?> localClass;
            try {
                localClass = Class.forName("com.android.internal.R$dimen");
                Object localObject = localClass.newInstance();
                int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString());
                statusHeight = context.getResources().getDimensionPixelSize(i5);
            } catch (Exception e) {
                e.printStackTrace();
            } 
        }
        return statusHeight;
    }
```

【实用】获取Android状态栏的方法