【问题标题】:TextView bold via XML file?TextView通过XML文件加粗?
【发布时间】:2011-07-08 09:23:36
【问题描述】:

有没有办法通过 XML 将 TextView 中的文本加粗?

<TextView
   android:textSize="12dip"
   android:textAppearance="bold"  -> ??
</TextView>

谢谢

【问题讨论】:

标签: android textview resources


【解决方案1】:

我有一个项目,其中有以下TextView

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:text="@string/app_name"
    android:layout_gravity="center" 
/>

所以,我猜你需要使用android:textStyle

【讨论】:

  • 我正在像这样使用库 &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="20dp" android:paddingRight="20dp" android:text="@string/start" android:textAppearance="@style/PtSansNarrowFont" android:textColor="@color/white" /&gt; style.xml &lt;style name="PtSansNarrowFont" parent="android:TextAppearance"&gt; &lt;!-- Custom Attr--&gt; &lt;item name="fontPath"&gt;fonts/pt-sans_narrow.ttf&lt;/item&gt; &lt;/style&gt; 不应用粗体
【解决方案2】:

只需使用

android:textStyle="bold"

【讨论】:

    【解决方案3】:

    例子:

    使用:android:textStyle="bold"

     <TextView
        android:id="@+id/txtVelocidade"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/txtlatitude"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="34dp"
        android:textStyle="bold"
        android:text="Aguardando GPS"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    

    【讨论】:

      【解决方案4】:

      使用 textstyle 属性为粗体

      android:textStyle = "bold";
      

      【讨论】:

        【解决方案5】:

        使用android:textStyle="bold"

        4 ways to make Android TextView Bold

        喜欢这个

        <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="12dip"
        android:textStyle="bold"
        />
        

        有很多方法可以使 Android TextView 加粗。

        【讨论】:

          【解决方案6】:
          Just you need to use 
          
          //for bold
          android:textStyle="bold"
          
          //for italic
          android:textStyle="italic"
          
          //for normal
          android:textStyle="normal"
          
          <TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textStyle="bold"
              android:text="@string/userName"
              android:layout_gravity="left"
              android:textSize="16sp"
          />
          

          【讨论】:

            猜你喜欢
            • 2017-01-23
            • 1970-01-01
            • 1970-01-01
            • 2018-01-13
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-08-09
            • 1970-01-01
            相关资源
            最近更新 更多