我不想自定义我的字体,我只想使用android studio.How中可用的字体,我要将文本的字体更改为无字体、衬线字体还是等宽字体?
发布于 2015-05-29 14:11:45
根据此Stackoverflow answer的-Hello
-android:typeface在xml中用于更改字体。
-You最终的代码是:-
<Textview .......... =android:typeface="normal/sans/monospace"..../>发布于 2015-05-29 14:33:30
首先download你需要的字体的.ttf文件(arial.ttf)。将其放置在assets文件夹中(在assest文件夹中创建名为"fonts“的新文件夹,并将其放入其中)。如果"txtyour“是你想要应用字体的文本,使用下面的代码,
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/arial.ttf");
txtview.setTypeface(type);发布于 2015-05-29 14:48:44
如果你想改变整个应用程序的字体,那么我会建议你使用样式。
只需将以下行添加到您的styles.xml文件中-
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/TextAppearance.Sans</item>
<item name="android:buttonStyle">@style/TextAppearance.Sans</item>
</style>
<style name="TextAppearance.Sans" parent="TextAppearance.AppCompat.Large">
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">normal</item>
</style>如果您不想在整个应用程序中更改字体,那么只需在您想要更改字体的每个样式中定义TextView元素,而不是在样式中进行设置-
<TextView
style="@style/TextAppearance.Sans"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>https://stackoverflow.com/questions/30522213
复制相似问题