如何改变文本/字体设置在一个Android TextView?

例如,如何使文本加粗?


当前回答

设置属性

android:textStyle="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"

在我的情况下,通过string.xml通过html标签传递值..

<string name="your_string_tag"> <b> your_text </b></string> .

设置属性

android:textStyle="bold"

假设你是Android Studio的新手, 你可以在设计视图XML中使用

android:textStyle="bold"          //to make text bold
android:textStyle="italic"        //to make text italic
android:textStyle="bold|italic"   //to make text bold & italic

你可以这样做

ty.setTypeface(Typeface.createFromAsset(ctx.getAssets(), "fonts/magistral.ttf"), Typeface.BOLD);