get StatusBar Height from Window - Android User Interface

Android examples for User Interface:StatusBar

Description

get StatusBar Height from Window

Demo Code


//package com.java2s;
import android.app.Activity;

import android.graphics.Rect;

import android.view.Window;

public class Main {
    public static int getStatusBarHeight(Activity activity) {
        if (activity == null) {
            return 0;
        }//from w  ww  . j av a 2  s .  c o  m
        Rect windowDisplayFrame = new Rect();
        Window window = activity.getWindow();
        if (window == null) {
            return 0;
        }
        window.getDecorView().getWindowVisibleDisplayFrame(
                windowDisplayFrame);
        return windowDisplayFrame.top;
    }
}

Related Tutorials