将TextAppearance添加到TabLayout

时间:2017-01-09 20:52:41

标签: android android-tablayout

我有这个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" />

我正在尝试为标题添加样式,但当我添加此行app:tabTextAppearance="@style/AppTabLayout"时,会出现此错误:

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 

1 个答案:

答案 0 :(得分:0)

我有同样的问题,直到我能够使用本网站的指南修复它。

https://guides.codepath.com/android/google-play-style-tabs-using-tablayout#styling-the-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"
    style="@style/MyCustomTabLayout"
/>

然后转到您的TabLayout并添加 style =&#34; @ style / MyCustomTabLayout&#34;

{{1}}