2016-04-03 32 views
1

私はさまざまな画面サイズ用にアプリケーションを設計していますが、私は小さな問題があります。タブ内のテキストのサイズを変更することはできません。ここに私がしたことがあります。タブ内のテキストサイズを変更する

まず自分のスタイルを作成しました。

<style name="MineCustomTabText" parent="TextAppearance.Design.Tab"> 
    <item name="android:textSize">22sp</item> 
</style> 

次に、このスタイルを適切なXMLファイルに使用します。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
tools:context="manutd.football.app.interviews.InterviewsActivity"> 

<manutd.football.app.SlidingTabLayout 
    android:id="@+id/tabs" 
    app:tabTextAppearance="@style/MineCustomTabText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="2dp" 
    android:background="#656e99" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_below="@+id/tabs" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:layout_weight="1" 
    ></android.support.v4.view.ViewPager> 

</RelativeLayout> 

ありがとう

答えて

6

さて私はあなたがあなたが

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout"> 
    <item name="tabMaxWidth">@dimen/tab_max_width</item> 
    <item name="tabIndicatorColor">?attr/colorAccent</item> 
    <item name="tabIndicatorHeight">2dp</item> 
    <item name="tabPaddingStart">12dp</item> 
    <item name="tabPaddingEnd">12dp</item> 
    <item name="tabBackground">?attr/selectableItemBackground</item> 
    <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item> 
    <item name="tabSelectedTextColor">?android:textColorPrimary</item> 
</style> 
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab"> 
    <item name="android:textSize">14sp</item> 
    <item name="android:textColor">?android:textColorSecondary</item> 
    <item name="textAllCaps">true</item> 
</style> 
+0

はい。完了しました。ヘルプ - ) – Theo

0

スタイルファイルで親を変更します。

<style name="MineCustomTabText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"> 
    <item name="android:textSize">22sp</item> 
</style> 
+0

TextAppearance.AppCompat.Widgetが認識されません。 – Theo

+0

SDKのターゲットと最小バージョンは何ですか? –

+0

これは16です... minSdkVersion 16 – Theo

3

ようなあなたのタブで欲しいものを変更することができ、このことにより、

<android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     style="@style/MyCustomTabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
</android.support.design.widget.TabLayout> 

を使用することができますmanutd.football.app.SlidingTabLayout

を選択した理由を知っているDNT tabTextAppearanceを使用して、タブ内のテキストのサイズを変更します。

app:tabTextAppearance="?android:attr/textAppearanceSmall" 

私TabLayoutの完全なコードは、これが役立ちます

<android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/tabLayoutBGColor" 
      app:tabSelectedTextColor="@color/colorAccent" 
      app:tabTextAppearance="?android:attr/textAppearanceSmall" 
      app:tabMode="fixed" 
      app:tabGravity="fill"/> 

希望です。

関連する問題