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
CodePudding user response:
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.