4
votes

I have a XF application using Toolbar which was added to my ContentPage like below:

public HomePage()
{
   InitializeComponent();
   var toolbarItem = new ToolbarItem
   {
      Text="Item1",
      Priority = 0,
      Order = ToolbarItemOrder.Primary,
   };

   if(Device.RuntimePlatform == Device.Android) {
      this.ToolbarItems.Add(toolbarItem);
   }
}

I wanted to change the height of the toolbar smaller than the original height. I edited the Toolbar.axml like below:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    style="@style/AppToolbarTheme"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:minHeight="0dp"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_scrollFlags="scroll|enterAlways" />

Unfortunately this has no effect whatsoever. Is there any other way to change the toolbar height?

1
Looking at the source code, it seems like it will always set the height of the toolbar to 56dp, which I believe is the value of the actionBarSize resource. Try using a custom NavigationPageRenderer, and get the toolbar there and see if you can set the height of it. github.com/xamarin/Xamarin.Forms/blob/…sme

1 Answers

6
votes

In your Android project, add an item called android:actionBarSize with your height in your style.xml file like this:

<?xml version="1.0" encoding="utf-8" ?>
<resources>

  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
     which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>
    <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>

    <!-- ********* CHECK HERE ********* -->
    <item name="android:actionBarSize">250dp</item>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
     <item name="colorAccent">#FF4081</item>
  </style>
</resources>