要调整Android TextView的样式,您可以在XML布局文件中使用内置的属性或者在Java/Kotlin代码中使用setTypeface()
方法。这里有一些常见的属性调整示例:
- 改变字体大小: 在XML布局文件中:
<TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:textSize="20sp" />
在Java/Kotlin代码中:
TextView textView = findViewById(R.id.textView);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
- 改变字体颜色: 在XML布局文件中:
<TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:textColor="#FF0000" />
在Java/Kotlin代码中:
TextView textView = findViewById(R.id.textView);
textView.setTextColor(Color.RED);
- 改变字体样式: 在XML布局文件中:
<TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:textStyle="bold" />
在Java/Kotlin代码中:
TextView textView = findViewById(R.id.textView);
textView.setTypeface(null, Typeface.BOLD);
- 改变字体粗细: 在XML布局文件中:
<TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:textWeight="bold" />
在Java/Kotlin代码中:
TextView textView = findViewById(R.id.textView);
textView.setTypeface(null, Typeface.BOLD);
这些只是一些基本的样式调整示例。您可以根据需要使用更多的属性来调整TextView的外观。