Android TabLayout与ViewPager搭配使用英

2017-05-19  本文已影响0人  滑稽的命运

问题:TabLayout与ViewPager搭配使用时英文标题默认大写

目的:让TabLayout的英文标题既能显示大写又能显示小写

步骤:

  1. 在style.xml中实现一个样式,指定parent为TextAppearance.Design.Tab,并设置标签属性<item name="textAllCaps">false</item>

    <style name="TabTextStyle" parent="TextAppearance.Design.Tab">
            <item name="textAllCaps">false</item>
    </style>
    
  2. 在布局的TabLayout标签中使用app:tabTextAppearance指定Tab的文字样式

     <android.support.design.widget.TabLayout
                app:tabTextAppearance="@style/TabTextStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
    

附上TabLayout默认字体样式代码

<style name="TextAppearance.Design.Tab" parent="TextAppearance.AppCompat.Button">
        <item name="android:textSize">@dimen/design_tab_text_size</item>
        <item name="android:textColor">?android:textColorSecondary</item>
        <item name="textAllCaps">true</item>
</style>
上一篇 下一篇

猜你喜欢

热点阅读