Xamarin Forms:如何在Android中更改工具栏高度? [英] Xamarin Forms: How to change Toolbar height in Android?

查看:82
本文介绍了Xamarin Forms:如何在Android中更改工具栏高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);
   }
}

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

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?

推荐答案

在您的Android项目中,像这样在您的style.xml文件中添加一个高度为android:actionBarSize的项目:

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>

这篇关于Xamarin Forms:如何在Android中更改工具栏高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆