Android StatusBar Size Get getStatusbarHeight(Activity activity)

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

Description

get Statusbar Height

Declaration

public static int getStatusbarHeight(Activity activity) 

Method Source Code

//package com.java2s;

import android.app.Activity;
import android.content.Context;

import android.graphics.Rect;

import android.util.DisplayMetrics;

public class Main {
    public static final int UI_DEFAULT_STATUSBAR_HEIGHT = 24;

    public static int getStatusbarHeight(Activity activity) {
        int statusbarHeight;
        try {/*from ww w  . j  ava 2  s .c  o  m*/
            Rect frame = new Rect();
            activity.getWindow().getDecorView()
                    .getWindowVisibleDisplayFrame(frame);
            statusbarHeight = frame.top;
        } catch (Exception e) {
            statusbarHeight = getDensityDimen(activity,
                    UI_DEFAULT_STATUSBAR_HEIGHT);
        }
        return statusbarHeight;
    }

    public static int getDensityDimen(Context context, int dimen) {
        final DisplayMetrics dm = context.getResources()
                .getDisplayMetrics();
        return ((int) (dimen * dm.density));
    }
}

Related

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