Xamarin Forms: How To Change Text Color Of Selected Tab Using Tabbedpagerenderer
I am developing Tabs using TabbedPageRenderer. I am not able to change text color of selected tab(Only getting change selected tab icon color). Below is MyTabbedPageRenderer.cs cla
Solution 1:
Xamarin Forms: How to change text color of selected tab using TabbedPageRenderer
There is no need to use TabbedPageRenderer
to change the selected tab text color, you can change it directly Via XML attributes.
In your Resource\layout\Tabbar.axml
:
<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.TabLayoutxmlns: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:tabMode="fixed"app:tabGravity="fill"app:tabTextColor="@color/your_unselected_text_color"app:tabSelectedTextColor="@color/your_selected_text_color"app:tabIndicatorColor="@color/your_indicator_color"
/>
Update:
Give your TextView
a ColorStateList
will solve this issue. In your MyTabbedPageRenderer
SetTabIcon
method:
protectedoverridevoidSetTabIcon(TabLayout.Tab tab, FileImageSource icon)
{
base.SetTabIcon(tab, icon);
tab.SetCustomView(Resource.Layout.Custom_tab_layou);
var imageview = tab.CustomView.FindViewById<ImageView>(Resource.Id.icon);
var tv = tab.CustomView.FindViewById<TextView>(Resource.Id.tv);
tv.SetText(tab.Text, TextView.BufferType.Normal);
imageview.SetBackgroundDrawable(tab.Icon);
ColorStateList colors2 = null;
if ((int)Build.VERSION.SdkInt >= 23)
colors2 = Resources.GetColorStateList(Resource.Color.icon_tab, Forms.Context.Theme);
else
colors2 = Resources.GetColorStateList(Resource.Color.icon_tab);
tv.SetTextColor(colors2);
}
Solution 2:
See if this might helpful to you How to change selected Tab text color you can use TabLayout instead like this:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><android.support.design.widget.TabLayoutandroid:layout_height="wrap_content"android:layout_width="match_parent"android:id="@+id/tablayout"app:tabTextColor="@color/colorPrimary"app:tabSelectedTextColor="@color/colorAccent"app:tabIndicatorColor="@android:color/holo_orange_light"><android.support.design.widget.TabItemandroid:text="tab 1"/><android.support.design.widget.TabItemandroid:text="tab 2"/><android.support.design.widget.TabItemandroid:text="tab 3"/></android.support.design.widget.TabLayout></LinearLayout>
Post a Comment for "Xamarin Forms: How To Change Text Color Of Selected Tab Using Tabbedpagerenderer"