Xamarin.forms 如何在Xamarin Forms Android应用程序中设置选项卡颜色

Xamarin.forms 如何在Xamarin Forms Android应用程序中设置选项卡颜色,xamarin.forms,Xamarin.forms,我正在为Android开发一个Xamarin应用程序,它在顶部使用一个标签条,如下所示:- <?xml version="1.0" encoding="utf-8" ?> <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="App.App"> &

我正在为Android开发一个Xamarin应用程序,它在顶部使用一个标签条,如下所示:-

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="App.App">
<Application.Resources>
    <ResourceDictionary>
        <!--Global Styles-->
        <Color x:Key="MainBackgroundColour">Black</Color>
        <Color x:Key="MainTextColour">Red</Color>
        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="{StaticResource MainBackgroundColour}" />
            <Setter Property="BarTextColor" Value="{StaticResource MainTextColour}" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

更改后,我只需更改选项卡底部的颜色(箭头指向的位置)。目前它是白色的,但我希望它设置为不同的颜色

我在MainPage.xaml中有以下内容:-

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:views="clr-namespace:App.Views"
        x:Class="App.Views.MainPage" BarBackgroundColor="#151c3e" BarTextColor="{StaticResource MainTextColour}">
<TabbedPage.Children>
    <NavigationPage Title="Location">
    <x:Arguments>
        <views:LocationPage />
    </x:Arguments>
    </NavigationPage>

其中,App.xaml中指定了mainTextColor,如下所示:-

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="App.App">
<Application.Resources>
    <ResourceDictionary>
        <!--Global Styles-->
        <Color x:Key="MainBackgroundColour">Black</Color>
        <Color x:Key="MainTextColour">Red</Color>
        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="{StaticResource MainBackgroundColour}" />
            <Setter Property="BarTextColor" Value="{StaticResource MainTextColour}" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

黑色
红色


有什么想法吗?

在android项目中,转到资源/layout/Tabbar.axml并将app:tabIndicatorColor的值更改为您想要的任何颜色

<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="@android:color/holo_red_dark"
app:tabGravity="fill"
app:tabMode="fixed" />


这是否回答了您的问题@安德鲁:是的,很有效,谢谢。我不知道为什么我之前没有看到那篇文章。谢谢。@GarryPilkington您现在似乎已经解决了您的问题,请记住标记任何有用的回复以关闭您的线程,谢谢。