Home > Back-end >  Changing ActionBar Height
Changing ActionBar Height

Time:12-24

I changed the ActionBar height in themes.xml with this

<item name="actionBarSize">30dp</item>

The height of ActionBar changes but then it throws the alignment of my first control off.

Before changing ActionBar height:

enter image description here

After changing Actionbar height

enter image description here

The first Spinner control is aligned to the top of the Layout

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.MainFragment">



<Spinner
    android:id="@ id/spSessionsMain"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:background="@drawable/background_spinner"
    android:spinnerMode="dropdown"
    app:layout_constraintLeft_toRightOf="parent"
    app:layout_constraintRight_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    />

I'm at a complete loss.

CodePudding user response:

This is happening because the Action bar has a min height of 64dp by default defined in its style :

ActionBar style : (Just for reference don't copy paste this in your theme)

<style name="Widget.MaterialComponents.Light.ActionBar.Solid" parent="Widget.AppCompat.Light.ActionBar.Solid">
  <item name="titleTextStyle">?attr/textAppearanceHeadline6</item>
  <item name="subtitleTextStyle">?attr/textAppearanceSubtitle1</item>
  <!-- Overrides minimum height in landscape to avoid headline6 and subtitle1 height concerns. -->
  <item name="android:minHeight">@dimen/mtrl_toolbar_default_height</item>
  <item name="maxButtonHeight">@dimen/mtrl_toolbar_default_height</item>
</style>

If you want to remove the gap between your spinner and the action bar you can override the min height of the bar. like this :

<style name="CustomActionBar" parent="Widget.MaterialComponents.Light.ActionBar.Solid">
   <item name="android:minHeight">30dp</item>
</style>

Then add this line to your main theme :

<item name="actionBarStyle">@style/CustomActionBar</item>
  • Related