Как отключить эффект увеличения метки в TabBar Xamarin Android? - PullRequest
0 голосов
/ 31 марта 2020

Когда я нажимаю на вкладку в панели вкладок, возникает эффект увеличения метки. Я хочу отключить этот эффект.

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

1 Ответ

1 голос
/ 31 марта 2020

Существует 2 просмотра текста, если оно равно BottomNavigationView (то есть, когда ToolbarPlacement.Bottom). По умолчанию при выборе оно имеет больший размер шрифта. Вам необходимо установить одинаковый размер для обоих TextView s либо в пользовательском рендере, либо в 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
    }
 }
...