如何更改 Xamarin.Droid 中标签页指示符的颜色?

How to change color of tabbed page indicator in Xamarin.Droid?

我正在使用 Xamarin.Forms 和便携式 Class 库构建应用程序。我有一个标签页。我想更改选项卡式页面指示器的颜色。更改布局的其余部分是我已经完成的事情,我唯一需要做的就是更改浅蓝色选项卡式页面指示器,如下所示:

我找不到任何可以在 Xamarin.Droid 中工作的内容。这是创建包含以下内容的选项卡式页面的代码:

class TabbedPageTry : TabbedPage
{
    public TabbedPageTry()
    { 
        Title = "TabbedPage";

        var myPages = new CategoryDAO().GetCategories();
        foreach (var item in myPages)
        {
            Children.Add(new TabPage(item.CategoryID) { BindingContext = item });
        }
    }

    public class TabPage : ContentPage
    {
        public TabPage(int categoryID)
        {
            Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);

            var listView = new ListView
            {

                SeparatorColor = Color.FromHex("#101010"),
                ItemsSource = new CourseDAO().GetCourses(),
                IsPullToRefreshEnabled = false,
                BackgroundColor = Color.White,
            };

            this.SetBinding(Page.TitleProperty, "Name");
            Content = listView;
        }
}

因为正在申请 Visual Studio 并且 Xamarin.Forms 我的问题还没有得到回答。我发现的所有问题都是针对 Android 的,这 NOT 我要找的。我需要的是针对我的问题的 C# 解决方案。

提前致谢。

如果您 using AppCompat 在 Android 平台项目中,请在 TabLayout axml 文件中使用 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"
   ....
    app:tabIndicatorColor="#123456" />

如果您使用的是FormsAppCompatActivity(Material设计),那么您所要做的就是打开droid项目的Resources文件夹中的Tabbar.axml文件并更改颜色设置app:tabIndicatorColor。例如,

<?xml version="1.0" encoding="utf-8"?>
<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="#FF3300" <!-- Set indicator color here, sets it to red-->
    app:tabGravity="fill"
    app:tabMode="fixed" />

mainview.xaml.cs里面publicMainView():

On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarSelectedItemColor(enter color here)

On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarItemColor(enter color here)