如何增加动作栏/工具栏大小和字体大小Xamarin multiplatform Android平板电脑?

时间:2017-10-31 14:33:54

标签: android xamarin multiplatform

所以我对Xamarin和移动开发人员来说相当新,我最近开始使用已在iOS完成的Android项目。我需要增加工具栏/操作栏的大小(不确定它是什么,但它是每页顶部的东西,允许你回到以前的屏幕,并在其中有页面标题),还有Android平板电脑的字体大小。然而,无论设备(手机或平板电脑)如何,我都无法改变尺寸。我尝试了很多东西,但没有任何效果。

这是我的styles.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> <!--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>-->
    <item name="android:textAllCaps">false</item>
    <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>
    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
    <item name="android:textCursorDrawable">@null</item>

    <!--<item name="android:actionBarStyle">@style/CustomActionBar</item>
    <item name="android:height">80dp</item>-->

    <!--Action bar style-->
    <item name="android:actionBarStyle">@style/MyTheme.ActionBar</item>
    <item name="actionBarStyle">@style/MyTheme.ActionBar</item>

</style>

<style name="MyTheme.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleText</item>
    <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleText</item>
    <item name="android:height">80dp</item>
    <item name="height">80dp</item>
</style>

<style name="MyTheme.ActionBar.TitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textSize">40dp</item>
    <item name="android:textColor">#00FFAA</item>
</style>
</resources>

我也分别在Widget.AppCompat.Light.ActionBar和TextAppearance.AppCompat.Widget.ActionBar.Title前面和没有@style尝试过,但仍然没有。有一些事情显而易见我做错了,但我不确定是什么。我们非常感谢你能提供的任何帮助。谢谢!

这是我登录的NavigationPage代码:

var newScreen = new DeviceListPage();
newScreen.Title = " ";
var nav = new NavigationPage(newScreen);
this.Navigation.PushModalAsync(nav);

这是DeviceListPage中的注销工具栏项:

<ContentPage.ToolbarItems>
    <ToolbarItem x:Name="tb" Text="Log Out" Clicked="btnLogOutClicked"> </ToolbarItem>
</ContentPage.ToolbarItems>

这里只是从DeviceListPage推送到主页的通用页面:

var newScreen = new MainPage(activeDeviceName);
newScreen.isFromDeviceList = true;
newScreen.Title = "Main Screen";
this.Navigation.PushAsync(newScreen);

更新!:好的,所以我想出了如何使用以下自定义渲染器更改工具栏上标题文本的字体大小:

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomToolBar))]
namespace MyHealthVitals.Droid
{
public class CustomToolBar : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
{

    private Android.Support.V7.Widget.Toolbar toolbar;

    public override void OnViewAdded(Android.Views.View child)
    {
        base.OnViewAdded(child);
        System.Diagnostics.Debug.WriteLine("child type = "+child.GetType().ToString());
        System.Diagnostics.Debug.WriteLine("child type fullname = " + child.GetType().FullName);
        System.Diagnostics.Debug.WriteLine("child type name = " + child.GetType().Name);
        if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
        {
            toolbar = (Android.Support.V7.Widget.Toolbar)child;
            toolbar.ChildViewAdded += Toolbar_ChildViewAdded;
        }
    }

    private void Toolbar_ChildViewAdded(object sender, ChildViewAddedEventArgs e)
    {
        var view = e.Child.GetType();
        if (e.Child.GetType() == typeof(Android.Widget.TextView))
        {
            var textView = (Android.Widget.TextView)e.Child;
            textView.SetTextSize(ComplexUnitType.Px, 80);
        }
    }
}
}

但是,我似乎还无法弄清楚如何更改ToolbarItem控件的字体大小。由于没有ToolbarItem Renderers,因此非常困难。

0 个答案:

没有答案