Solution 1 :
Use tabBackground
app:tabBackground="@color/colorPrimary"
Problem :
Android tab layout background color is white when it should be trasparent.
It won’t pick up the colorPrimary in the below code:
<?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" // Should pick up transparent
here?
android_theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android_backgroundTint="#5C328A"
app_tabTextColor="@color/button_material_light"
app_tabSelectedTextColor="@android:color/black"
app_tabIndicatorColor="@android:color/white"
app_tabGravity="fill"
app_tabMode="fixed" />
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="launcher_background">#FFFFFF</color>
<color name="colorPrimary">@android:color/transparent</color>
<color name="colorPrimaryDark">#E3E31E</color>
<color name="colorAccent">#FF4081</color>
</resources>
Xaml tabs on page:
<Grid
BackgroundColor="black"
ColumnSpacing="0"
HorizontalOptions="FillAndExpand"
RowSpacing="0">
<Grid.RowDefinitions >
<RowDefinition Height="50" />
<RowDefinition Height="8" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
//Closing tags below
MainActivity.cs:
protected override void OnCreate(Bundle savedInstanceState)
{
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.SetTheme(Resource.Style.MainTheme);
base.OnCreate(savedInstanceState);
global::Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
global::Xamarin.Forms.FormsMaterial.Init(this, savedInstanceState);
global::Xamarin.FormsMaps.Init(this, savedInstanceState);
LoadApplication(new App(new AndroidInitializer()));
}
I’ve gone through a number of stack overflow questions regarding tab layout and i can’t find any difference in my code compared to the accepted solutions.
Comments
Comment posted by clearyb123
This still doesn’t pick it up unfortunately. Am I missing some configuration file/ method?
Comment posted by Gobu CSG
Remove your theme and background as well… May be imapct