如何根据屏幕大小更改 Android ViewPager 页面标题文本大小
How to change Android ViewPager page title text size depending on the screen size
在平板电脑上 ViewPager
和 运行 中有 3 个页面,而在智能手机上 运行 页面标题的文本大小必须改变。
任何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>
I try to set PagerTabStrip text size in the xml but that was not
possible
是吗?因为你绝对可以做到。如果您查看 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>
values-sw600dp
<resources>
<dimen name="pagerTitleTextSize">64sp</dimen>
</resources>
如果您想以编程方式处理它,还有 PagerTitleStrip.setTextSize
。
在平板电脑上 ViewPager
和 运行 中有 3 个页面,而在智能手机上 运行 页面标题的文本大小必须改变。
任何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>
I try to set PagerTabStrip text size in the xml but that was not possible
是吗?因为你绝对可以做到。如果您查看 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>
values-sw600dp
<resources>
<dimen name="pagerTitleTextSize">64sp</dimen>
</resources>
如果您想以编程方式处理它,还有 PagerTitleStrip.setTextSize
。