android textView字体样式
时间: 2023-11-18 12:06:37 浏览: 186
在 Android 中,可以通过设置 TextView 的字体样式来改变字体的外观。下面是一些常见的字体样式设置:
1. 设置字体颜色:可以通过 setTextColor() 方法设置字体颜色,例如:
```
textView.setTextColor(Color.BLUE);
```
2. 设置字体大小:可以通过 setTextSize() 方法设置字体大小,例如:
```
textView.setTextSize(20);
```
3. 设置字体粗细:可以通过 setTypeface() 方法设置字体粗细,例如:
```
textView.setTypeface(null, Typeface.BOLD);
```
4. 设置字体风格:可以通过 setTypeface() 方法设置字体风格,例如:
```
textView.setTypeface(null, Typeface.ITALIC);
```
还可以通过 XML 文件来设置字体样式,例如:
```
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold|italic" />
```
其中,textStyle 属性可以设置字体风格,可以设置为 normal、bold、italic、bolditalic。
阅读全文
相关推荐






