是否有一种方法来设置TextView的textStyle属性编程?似乎没有setTextStyle()方法。
需要明确的是,我不是在谈论视图/小部件样式!我说的是以下几点:
<TextView
android:id="@+id/my_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World"
android:textStyle="bold" />
由于setTextAppearance(resId)仅适用于API 23及以上版本,请使用:
TextViewCompat。setTextAppearance (textViewGoesHere渣油)
该方法在内部实现如下:
public static void setTextAppearance(@NonNull TextView textView, @StyleRes int resId) {
if (Build.VERSION.SDK_INT >= 23) {
textView.setTextAppearance(resId);
} else {
textView.setTextAppearance(textView.getContext(), resId);
}
}