Xamarin Forms:如何在Android中更改工具栏高度?

我有一个使用工具栏的XF应用程序,它已添加到我的ContentPage中,如下所示:

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

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

我想将工具栏的高度更改为小于原始高度.我编辑了Toolbar.axml,如下所示:

<?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" />

不幸的是,这没有任何作用.还有其他更改工具栏高度的方法吗?

最佳答案
在您的Android项目中,添加一个名为android:actionBarSize的项目,并将其高度添加到style.xml文件中,如下所示:

<?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>

转载注明原文:Xamarin Forms:如何在Android中更改工具栏高度? - 代码日志