Android - Standard height of toolbar

The recommended minimum size for touchable elements is 48 dp, see this page for more detailed metrics.


In addition to @vedant1811 answer, you can programmatically obtain actionBarSize from attrs:

TypedValue tv = new TypedValue();
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
    actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
}

Its best to use ?attr/actionBarSize as @Jaison Brooks commented.

In the material guidelines, suggested height is 56dp:

Toolbar: 56dp


You can use the following method to get the AppBar height programatically

private static final int DEFAULT_TOOLBAR_HEIGHT = 56;

private static int toolBarHeight = -1;

public static int getToolBarHeight(Context context) {
        if (toolBarHeight > 0) {
            return toolBarHeight;
        }
        final Resources resources = context.getResources();
        final int resourceId = resources.getIdentifier("action_bar_size", "dimen", "android");
        toolBarHeight = resourceId > 0 ?
                resources.getDimensionPixelSize(resourceId) :
                (int) convertDpToPixel(DEFAULT_TOOLBAR_HEIGHT);
        return toolBarHeight;
    }

public static float convertDpToPixel(Context context, float dp) {
    float scale = context.getResources().getDisplayMetrics().density;
    return dp * scale + 0.5f;
}