如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
如何改变文本/字体设置在一个Android TextView?
例如,如何使文本加粗?
当前回答
要在layout.xml文件中这样做:
android:textStyle
例子:
android:textStyle="bold|italic"
程序上的方法是:
setTypeface(Typeface tf)
设置应显示文本的字体和样式。注意,并不是所有字体家族都有粗体和斜体变体,所以你可能需要使用setTypeface(Typeface, int)来获得你真正想要的外观。
其他回答
最好的方法是:
TextView tv = findViewById(R.id.textView);
tv.setTypeface(Typeface.DEFAULT_BOLD);
要在layout.xml文件中这样做:
android:textStyle
例子:
android:textStyle="bold|italic"
程序上的方法是:
setTypeface(Typeface tf)
设置应显示文本的字体和样式。注意,并不是所有字体家族都有粗体和斜体变体,所以你可能需要使用setTypeface(Typeface, int)来获得你真正想要的外观。
在我的情况下,通过string.xml通过html标签传递值..
<string name="your_string_tag"> <b> your_text </b></string> .
这是解决方案
TextView questionValue = (TextView) findViewById(R.layout.TextView01);
questionValue.setTypeface(null, Typeface.BOLD);
在values文件夹中的style.xml文件中定义一个新的样式,使用您想要的格式
<style name="TextViewStyle" parent="AppBaseTheme">
<item name="android:textStyle">bold</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">#5EADED</item>
</style>
然后通过编写以下带有TextView属性的代码将此样式应用到TextView
style="@style/TextViewStyle"