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

例如,如何使文本加粗?


当前回答

editText.setTypeface(Typeface.createFromAsset(getAssets(), ttfFilePath));
etitText.setTypeface(et.getTypeface(), Typeface.BOLD);

将字体和样式都设置为粗体。

其他回答

最好的方法是:

TextView tv = findViewById(R.id.textView);
tv.setTypeface(Typeface.DEFAULT_BOLD);

你可以简单地做以下几点:

以XML格式设置属性

  android:textStyle="bold"

从程序上看,方法是:

TextView Tv = (TextView) findViewById(R.id.TextView);

Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);

Tv.setTypeface(boldTypeface);

希望这能帮到你,谢谢。

如果你在画它,那么这个就可以做到:

TextPaint.setFlags(Paint.FAKE_BOLD_TEXT_FLAG);

你可以这样做

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

在使用自定义字体,但没有粗体字体的情况下,可以使用:

myTextView.setText(Html.fromHtml("<b>" + myText + "</b>");