如何在TabBar Xamarin Android中禁用增加标签的效果?

问题描述 投票:-1回答:1

当我单击选项卡上的选项卡时,会出现增加标签的效果。我想禁用此效果。

enter image description here

在MainPage.xaml中

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="App1.MainPage"
            xmlns:local1="clr-namespace:App1;assembly=App1"
            xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
            android:TabbedPage.IsSwipePagingEnabled="False"
            BarBackgroundColor ="White" IsHidden="True"
            SelectedTabColor="#ad1457">

    <TabbedPage.Children>
        <NavigationPage Title="Four" BarBackgroundColor = "#ffffff"  BarTextColor="Black" Icon="icon1.png">
            <x:Arguments>
                <local1:Page1 />
            </x:Arguments>
        </NavigationPage>

        <NavigationPage Title = "Five" BarBackgroundColor = "#ffffff"  BarTextColor="Black" Icon="icon1.png">
            <x:Arguments>
                <local1:Page2 />
            </x:Arguments>
        </NavigationPage>

        <NavigationPage Title = "Six" BarBackgroundColor = "#ffffff"  BarTextColor="Black" Icon="icon1.png">
            <x:Arguments>
                <local1:Page3 />
            </x:Arguments>
        </NavigationPage>
    </TabbedPage.Children>
</TabbedPage>

在MainPage.xaml.cs中

public MainPage()
    {
        InitializeComponent();
        On<Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
    }
c# android xamarin xamarin.forms xamarin.android
1个回答
1
投票

如果是BottomNavigationView,则有2个文本视图(即ToolbarPlacement.Bottom时)默认情况下,选中它时,它具有更大的字体大小。您需要在自定义渲染器或TextView中为两个Platform Effect设置相同的大小。

这里是代码

{
    if (!(Container.GetChildAt(0) is ViewGroup layout))
        return;

    if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView))
        return;

    var bottomNavMenuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;

    for (int i = 0; i < bottomNavMenuView.ChildCount; i++)
    {
        var item = bottomNavMenuView.GetChildAt(i) as BottomNavigationItemView;
        var itemTitle = item.GetChildAt(1);

        var smallTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(0));
        var largeTextView = ((TextView)((BaselineLayout)itemTitle).GetChildAt(1));

        smallTextView.SetTextSize(Android.Util.ComplexUnitType.Sp, 8);// this is unselected textview size
        largeTextView.SetTextSize(Android.Util.ComplexUnitType.Sp, 8); //this is selected textview size
    }
 }
© www.soinside.com 2019 - 2024. All rights reserved.