get Display Height Without Status Bar - Android android.app

Android examples for android.app:Display

Description

get Display Height Without Status Bar

Demo Code

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.view.Window;

public class Main {

  public static int getDisplayHeightWithoutStatusBar(Context context) {
    return getDisplayHeight(context) - getStatusBarHeight(context);
  }/*  w w w  .  ja  v  a 2  s.co m*/

  public static int getStatusBarHeight(Context context) {
    Rect rect = new Rect();
    Window window = ((Activity) context).getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    return rect.top;
  }

  public static int getDisplayHeight(Context context) {
    return context.getResources().getDisplayMetrics().heightPixels;
  }

}

Related Tutorials