如何在列表视图中设置自定义字体
问题描述:
欢迎 我有一个listview,其任务是显示字符串文件“内部”数组中的文本,并通过单独的行文件格式化文本我已经能够从该行的文件,但我想设置的文本行我已经搜查了很多,并没有解决问题的题中更改文本颜色...如何在列表视图中设置自定义字体
排文件的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/row_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="text"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
/>
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/line"/>
</LinearLayout>
答
1 - 将您最喜欢的字体添加到资产文件夹(Roboto.ttf)中。例如,
2 - 将其添加到您的代码中。
Typeface tf= Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf");
Textview.setTypeface(tf);
+0
我试过但这不起作用 –
你似乎缺少了你的问题的一些代码 –
也许这些帖子可以帮助您: http://stackoverflow.com/questions/7361135/how-to-change-color-and-font-on -listview http://stackoverflow.com/questions/18896887/android-change-listview-font-and-color – SergeS