2017-08-11 45 views
2

我想縮小選項卡文本大小的大小,因爲它會被切斷爲長文本。我已經嘗試了下面的解決方案,但它似乎並沒有工作。爲選項卡式頁面選項卡文本設置自定義字體大小

<style name="MainTheme" parent="MainTheme.Base"> 
    </style> 
    <!-- Base theme applied no matter what API --> 
    <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:--> 
    <item name="windowNoTitle">true</item> 
    <!--We will be using the toolbar so no need to show ActionBar--> 
    <item name="windowActionBar">false</item> 
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette --> 
    <!-- colorPrimary is used for the default action bar background --> 
    <item name="colorPrimary">#2196F3</item> 
    <!-- colorPrimaryDark is used for the status bar --> 
    <item name="colorPrimaryDark">#1976D2</item> 
    <!-- colorAccent is used as the default value for colorControlActivated 
     which is used to tint widgets --> 
    <item name="colorAccent">#FF4081</item> 
    <!-- You can also set colorControlNormal, colorControlActivated 
     colorControlHighlight and colorSwitchThumbNormal. --> 
    <item name="windowActionModeOverlay">true</item> 

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item> 

    <item name="android:actionBarTabTextStyle">@style/CustomTab</item> 
    <item name="actionBarTabTextStyle">@style/CustomTab</item> 
    </style> 

    <style name="CustomTab" 
     parent="@style/Widget.AppCompat.Light.ActionBar.TabText"> 
    <item name="android:textSize">5sp</item> 
    </style> 

有人能幫幫我嗎?

回答

5

在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">5sp</item> 
    </style> 

在Tabbar.axml

<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/sliding_tabs" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/colorPrimary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:tabIndicatorColor="@android:color/white" 
    style="@style/MyTabLayout" 
    app:tabGravity="fill" 
    app:tabMode="fixed" /> 

enter image description here

+0

哇,謝謝。奇蹟般有效。 – CaptainHere

+0

嗨,我已經寫你的給我的styles.xml文件的代碼,但不是運氣,請猜猜我有什麼想念。 – Deepak

+0

不知道你錯過了什麼 –

相關問題