如何设置运行时创建的TextView的字体?
How to set the font of a TextView created at runtime?
我创建了一个 TextView
I created a TextView
Textview tv = new TextView(this); tv.setTextSize(20);我可以轻松更改大小,现在我想将字体样式设置为Verdana".
I can easily change the size, now I'd like to set font style to "Verdana".
如何做到这一点?
推荐答案在运行时设置内置字体:
首先,要改变字体,一个 字体 使用了类.
To set In-built Font at Run-Time:
First of all, To Change Font-face, a Typeface class is used.
现在,在运行时,设置字体,使用setTypeface(Typeface) 来自 Java 代码
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" />在您的 Android 应用程序中设置自定义字体
为此,只需在项目根目录中创建一个 assets/文件夹,并将您的字体(以 TrueType 或 TTF 形式)放入资产中.例如,您可以创建 assets/fonts/ 并将您的 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
发布评论