Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.Activity; import android.graphics.Rect; import android.view.Window; public class Main { public static int $titleBarHeight(Activity activity) { int contentTop = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop(); int titleBarHeight = contentTop - getStatusHeight(activity); return titleBarHeight; } /** * @param activity * @return > 0 success; <= 0 fail */ public static int getStatusHeight(Activity activity) { int statusHeight = 0; Rect localRect = new Rect(); activity.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 = activity.getResources().getDimensionPixelSize(i5); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | IllegalArgumentException | SecurityException | NoSuchFieldException e) { e.printStackTrace(); } } return statusHeight; } }