简体   繁体   中英

Change color tabindicatorcolor xamarin forms

I want to change the tabindicatorcolor in MainPage.xaml but I cannot see the properties tabindicatorcolor. They mention here using AppCompat , I already imported the Android Support Library v7 AppCompat from NuGet and mentioned to check it here Resources/layout/Tabbar.axml but I cannot see in my MyProject.Android project.

What else did I missed? Sorry, just new with programming. Edit: I'm using Xamarin.Forms

Create a layout folder inside you Resources folder of Android platform of Xamarin.Forms project.

Then create tabbar.xml in the layout folder. Add the code below for the file. I set indicator color to red for reference.

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.tabs.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"
app:tabGravity="fill"
app:tabMode="fixed" />

And do not forget to set the TabLayoutResource in MainActivity.

 protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        TabLayoutResource= Resource.Layout.tabbar;

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
    }

For now, when you use the tabbedpage in Xamarin.Forms, you would have a red tabindicatorcolor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM