Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

I'm building an application with Xamarin.Forms and a Portable Class Library. I have a tabbed page. I want to change the color of the tabbed page indicator. Changing the rest of the layout is something I already managed, the only thing I do need is to change the light blue tabbed page indicator like shown below:
enter image description here

I couldn't find anything that could work in Xamarin.Droid. This is the code that creates the tabbed page with content:

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

Because the application is being made Visual Studio with Xamarin.Forms my question is not answered yet. All the question I found are for Android specific, this is NOT what I am looking for. What I need is the C# solution to my problem.

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are using AppCompat in your Android platform project, in your TabLayout axml file use the tabIndicatorColor property to do this:

<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" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...