Carlos Guerrero
Carlos Guerrero

Reputation: 372

Add TextAppearance to TabLayout

I have this TabLayout:

 <android.support.design.widget.TabLayout
    android:id="@+id/tab_layout_chef_my_menu"
    android:background="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top" />

And I'm trying to add style to the titles, but When I add this line app:tabTextAppearance="@style/AppTabLayout" this error shows up:

java.lang.NullPointerException
    at android.support.design.widget.TabLayout.<init>(TabLayout.java:344)
    at android.support.design.widget.TabLayout.<init>(TabLayout.java:285)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at 

Upvotes: 1

Views: 2611

Answers (1)

Chukwuemeka Ihedoro
Chukwuemeka Ihedoro

Reputation: 605

I had the same issue until i was able to fix it using the guide in this website.

https://guides.codepath.com/android/google-play-style-tabs-using-tablayout#styling-the-tablayout

According to the article you need to first create your styles in this manner:

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
</style>

<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:textStyle">bold</item>
</style>

Then go to your TabLayout and add style="@style/MyCustomTabLayout"

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout_chef_my_menu"
    android:background="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    style="@style/MyCustomTabLayout"
/>

Upvotes: 2

Related Questions