【问题标题】:How to Set Tab Color in Xamarin Forms Android App [duplicate]如何在 Xamarin Forms Android 应用程序中设置选项卡颜色 [重复]
【发布时间】:2020-03-13 09:47:25
【问题描述】:

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

我改变后的只是标签底部的颜色(箭头指向的地方)。目前它是白色的,但我希望它设置为不同的颜色。

我的 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 中指定 MainTextColour 的位置如下:-

<?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>

有什么想法吗?

【问题讨论】:

  • @Andrew - 是的,谢谢。不知道为什么我之前没有看到那个帖子。谢谢。
  • @GarryPilkington 看来您的问题已经解决了,请记得标记任何有用的回复以关闭您的帖子,谢谢。

标签: xamarin.forms


【解决方案1】:

在 android 项目中,转到 Resources/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" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-22
    • 1970-01-01
    • 2019-11-10
    • 2011-07-06
    • 1970-01-01
    • 2021-03-27
    • 2019-03-25
    • 1970-01-01
    相关资源
    最近更新 更多