如何设置PagerTabStrip的文字样式为粗体? [英] How to set TextStyle of PagerTabStrip to Bold?

查看:380
本文介绍了如何设置PagerTabStrip的文字样式为粗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ViewPager 使用 PagerTabStrip 来显示每个网页的标题。这里是我的XML code:

I'm using PagerTabStrip in ViewPager to show the title of each page. Here is my XML code:

<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" 
    android:background="@drawable/bg">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
    <android.support.v4.view.PagerTabStrip
            android:id="@+id/pager_title_strip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="#33b5e5"
            android:textColor="#a4c639"
            android:paddingTop="4dp"
            android:paddingBottom="4dp" />
    </android.support.v4.view.ViewPager>

</RelativeLayout>

我想设置的文本样式,以大胆 PagerTabStrip 是这样的: 安卓TEXTSTYLE =黑体。但是,这是不可能的 PagerTabStrip 。好像它只有文本颜色属性的文本。什么是我可以设置风格大胆的方式?

I want to set the textStyle to bold in PagerTabStrip like this: android:textStyle="bold". But this is not possible in PagerTabStrip. Seems like it has only textcolor property for text. What is the way by which I can set the style to bold?

推荐答案

您需要做的是创造文本样式,然后使用android:textAppearance属性...

What you need to do is create a style for the text, and then use the android:textAppearance attribute...

也许是这样的:

 <style name="PagerTabStripText">
      <item name="android:textSize">14sp</item>
      <item name="android:textStyle">bold</item>
      <item name="android:textColor">#a4c639</item>
 </style>

,然后在PagerTabStrip XML做到这一点:

And then in your PagerTabStrip XML do this:

 <android.support.v4.view.PagerTabStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:paddingTop="4dp"
        android:paddingBottom="4dp" 
        android:textAppearance="@style/PagerTabStripText"/>

这篇关于如何设置PagerTabStrip的文字样式为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆