Android StatusBar Size Get getStatusBarHeight(Activity activity)

Here you can find the source of getStatusBarHeight(Activity activity)

Description

get Status Bar Height

Declaration

public static int getStatusBarHeight(Activity activity) 

Method Source Code

//package com.java2s;
import java.lang.reflect.Field;

import android.app.Activity;

public class Main {
    public static int getStatusBarHeight(Activity activity) {
        try {/*from ww  w .  j a v a2 s  .c  o  m*/
            Class<?> clazz = Class.forName("com.android.internal.R$dimen");
            Object object = clazz.newInstance();
            Field field = clazz.getField("status_bar_height");
            int dpHeight = Integer.parseInt(field.get(object).toString());
            return activity.getResources().getDimensionPixelSize(dpHeight);
        } catch (Exception e1) {
            e1.printStackTrace();
            return 0;
        }
    }
}

Related

  1. getStatusBarHeight(Activity activity)
  2. getStatusBarHeight(Context context)
  3. getStatusbarHeight(Activity activity)