Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

android font size of tabs

i ask this quest for a few time ago , but i get no solutions :( my problem is, that i have an android app with a tab activity, where i have to set the font size of my tabs, but i don't know how.

in my activity i set my tabs programmatically:

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("MY TAB 1"));
    tabLayout.addTab(tabLayout.newTab().setText("MY TAB 2"));
    tabLayout.addTab(tabLayout.newTab().setText("MY TAB 3"));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

Problem is, that the last 1 - 2 letters will be cut, so i have to set the font size smaller, but how?

i hope anyone can help me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Write these below codes in styles.xml

<style name="MyTabLayout" parent="Base.Widget.Design.TabLayout">
        <item name="tabTextAppearance">@style/MyTabTextAppearance</item>
</style>

<style name="MyTabTextAppearance" parent="TextAppearance.AppCompat.Button">
        <item name="android:textSize">18sp</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="textAllCaps">true</item>
</style>

And in your tablayout, set the style like below.

<android.support.design.widget.TabLayout
     style="@style/MyTabLayout"
     android:layout_width="width"
     android:layout_height="height"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...