1

Recently I'm start using MDC's tabLayout and with the help of some answers of stackoverflow I'm able to change tabTextAppearance from xml -

<com.google.android.material.tabs.TabLayout
        android:id="@+id/customTabLayout"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_gravity="center_horizontal"
        android:background="#FFFFFF"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:tabGravity="fill"
        app:tabIndicator="@drawable/{custom_drawable_to_decrease_the_width_of_the_indicator}"
        app:tabIndicatorFullWidth="false"
        app:tabIndicatorHeight="1dp"
        app:tabMaxWidth="0dp"
        app:tabMode="scrollable"
        app:tabRippleColor="@null"
        app:tabTextAppearance="@style/CustomTabLayoutTextStyle" >

and In the CustomTabLayoutTextStyle I'm able to change the size, styles -

<style name="CustomTabLayoutTextStyle" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
    <item name="android:textSize">12sp</item>
    <item name="android:textStyle">normal</item>
</style>

But Now, I don't want to use xml and instead created a CustomView extending Material TabLayout and set these attributes programatically. I've successfully able to set almost all of the attributes -

 this.tabMode = MODE_SCROLLABLE
 this.tabRippleColor = null
 this.isTabIndicatorFullWidth = false
 this.minimumWidth = 0
 this.tabGravity = GRAVITY_FILL

But the problem is I cannot able to set the tabTextAppearance value programatically. I want to add CustomTabLayoutTextStyle programatically to get that style in my custom TabLayout. (I'm using matrial:1.4.0 in my project)

Anyone would you please give me some idea on how can I add customTextStyle on Material TabLayout programatically?

Thanks & Regards

mefahimrahman
  • 197
  • 2
  • 6
  • 29
  • I was looking something like this https://stackoverflow.com/questions/5051753/how-do-i-apply-a-style-programmatically/19690509#19690509 but for material Layout this setTextAppearance is not working – mefahimrahman Mar 10 '22 at 11:44

0 Answers0