如何在Android中更改字体样式和面部?

时间:2011-09-22 10:10:41

标签: android fonts

我想更改android中的字体和样式。这该怎么做?我正在使用模拟器。这可能会在模拟器中更改。是否有任何权限可以做到这一点。提前致谢。

6 个答案:

答案 0 :(得分:26)

在Android中只有五个fonttype-face

字体

Typeface.DEFAULT
Typeface.MONOSPACE
Typeface.SANS_SERIF
Typeface.DEFAULT_BOLD
Typeface.SERIF

和font-type

Typeface.NORMAL
Typeface.BOLD
Typeface.BOLD_ITALIC
Typeface.ITALIC

你可以像

一样使用
textView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);

和其他方式是download any .ttf file并将其放在资产文件夹中并像这样使用

Typeface type=Typeface.createFromAsset(context.getAssets(),
        "DroidSansMono.ttf");
textView.setTypeface(type, null);

答案 1 :(得分:4)

您可以更改XML文件中的字体样式和字体。例如,如果您想要更改Button的样式和面部。在xml中选择您的按钮,然后按照以下方法:

Button -> Right Click -> Properties -> Typeface and style

希望这会对你有所帮助。

答案 2 :(得分:3)

如果您想更改代码;

这是一个很好的参考;

http://mobile.tutsplus.com/tutorials/android/customize-android-fonts/

答案 3 :(得分:2)

你想要什么?是否要在textview中更改文本的字体和样式。如果是,那么使用这个

Typeface type = Typeface.createFromAsset(this.getAssets(),"your font name");
text.setTypeface(type);

对于样式,请使用以下链接:

  1. Style-resource

  2. Themes

答案 4 :(得分:1)

如果您想在Android应用程序中使用非默认字体(如“Helvetica”),请将字体文件(Helvetic.ttf)放在assets文件夹中,并使用以下代码:

Typeface tf= Typeface.createFromAsset(getAssets(), "Helvetica.ttf");
  TextView mTextView =(TextView) findViewById(R.id.text);
    mTextView.setTypeface(tf);

答案 5 :(得分:1)

如果你想使用自定义字体jus下载.ttf文件并将文件放入assets文件夹 并使用这样:

TextView tv=(TextView)findViewById(R.id.textView);
Typeface  tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/arial.ttf");
tv.setTypeface(tf);