在运行时,TextView中设置的字体 [英] set font at runtime, Textview

查看:119
本文介绍了在运行时,TextView中设置的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置字体的TextView,这是在运行时创建?

How to set font to textview, which is created at runtime?

我创建的TextView

i created textview

Textview tv = new TextView(this);      
tv.setTextSize(20);

就像我可以改变大小
我想设置字体样式为宋体。

like I can change the size
i want to set font style to "Verdana".

如何做到这一点? 问候 shishir

How to do this?? regards shishir

推荐答案

  • 首先,要改变字体,脸, 字样 类使用。

现在, 在运行时 ,设置字体面,使用 setTypeface(字体) 从Java code

Now, at Run-Time, to set the font-face, Use setTypeface(Typeface) from the Java code

例如:

<TextView android:text="@+id/TextView01"
 android:id="@+id/TextView01"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:textSize="30px"
 android:textStyle="italic"
 android:typeface="serif" />


设置自定义的字体(S)的Andr​​oid应用程序

要做到这一点,只需创建一个资源/文件夹中的项目的根,并把你的字体(在TrueType字体,或TTF,形式)的资产。你可能,例如,创建 资产/字体/ ,并把你的TTF文件有:


To set Custom font(s) in your Android application

To do this, simply create an assets/ folder in the project root, and put your fonts (in TrueType, or TTF, form) in the assets. You might, for example, create assets/fonts/ and put your TTF files in there:

  TextView tv=(TextView)findViewById(R.id.custom); 
  Typeface face=Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf"); 
  tv.setTypeface(face); 

这篇关于在运行时,TextView中设置的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆