2017-08-07 172 views
0

ViewPager中拥有3个页面并在平板电脑上运行vs在智能手机上运行时,页面标题的文本大小必须更改。如何根据屏幕大小更改Android ViewPager页面标题文本大小

任何ide?

我尝试在XML设置PagerTabStrip文字大小,但是这是不可能的

<android.support.v4.view.ViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?android:attr/windowBackground"> 

    <android.support.v4.view.PagerTabStrip 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

</android.support.v4.view.ViewPager> 

回答

1

我尝试设置PagerTabStrip文字大小在XML但这不是 可能

你是否?因为你绝对可以做到这一点。如果您看一下PagerTitleStrip source,您会看到它使用以下属性来设置标题文本的样式。

private static final int[] ATTRS = new int[] { 
    android.R.attr.textAppearance, 
    android.R.attr.textSize, 
    android.R.attr.textColor, 
    android.R.attr.gravity 
}; 

,你可以设置那些在XML中的任何一个,所以你的情况是这样的:

<android.support.v4.view.PagerTabStrip 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/pagerTitleTextSize" /> 

哪里pagerTitleTextSize就是在任何你需要的values文件夹中的文本大小。例如:

values

<resources> 

    <dimen name="pagerTitleTextSize">22sp</dimen> 

</resources> 

phone

values-sw600dp

<resources> 

    <dimen name="pagerTitleTextSize">64sp</dimen> 

</resources> 

tablet

还有PagerTitleStrip.setTextSize如果你想以编程方式处理它。

+1

谢谢你很奇怪你的权利不知道发生了什么事 – Erik