I can set my ActionBar height in my styles.xml resource file:
<style name="AppTheme" parent="Theme.MaterialComponents.Light"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="actionBarSize">40dp</item> </style> This way, my action bar is a bit smaller than the default one. But a white gap appears below the ActionBar. The content starts at the same position as if the ActionBar had the same height.
EDIT:
My layout file:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/mainMenuLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top"> <FrameLayout android:id="@+id/mmContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@id/mmBottomNavigation" /> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/mmBottomNavigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" app:menu="@menu/bottom_navigation_menu" app:itemBackground="@color/white" app:itemIconTint="@color/btn_nav_itam_color" app:itemTextColor="@color/btn_nav_itam_color" /> </RelativeLayout> EDIT 2: I tried it on a blank Application. The actionBarSize attribute works as expected. Also there's no white gap.
My app uses a custom layout for the action bar - custom_action_bar.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="0dp" android:layout_margin="0dp" android:background="@color/colorPrimary" > <TextView android:id="@+id/titleTvLeft" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="@string/app_name" android:textColor="@color/actionBarText" android:textSize="16sp" android:textStyle="bold" /> <TextView android:id="@+id/titleTvRight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:text="@string/title_bar_loggedin" android:textColor="@color/actionBarDarkText" android:textSize="12sp" android:textStyle="bold" /> </RelativeLayout> And this layout is set in the Activity:
public static void setCustomTitle(AppCompatActivity apc, String userName) { if (apc.getSupportActionBar() != null) { apc.getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); apc.getSupportActionBar().setDisplayShowCustomEnabled(true); apc.getSupportActionBar().setCustomView(R.layout.custom_action_bar); View view = apc.getSupportActionBar().getCustomView(); TextView tvLeft = (TextView) view.findViewById(R.id.titleTvLeft); TextView tvRight = (TextView) view.findViewById(R.id.titleTvRight); tvLeft.setText(apc.getResources().getString(R.string.app_name)); String rightTitle = apc.getResources().getString(R.string.title_bar_loggedin) + " " + userName; tvRight.setText(rightTitle); } } 
