我的目标是SDK 27版本
我在布局中使用这个:
<TextView
android:id="@+id/logo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:fontFamily="@font/source_sans_pro_regular"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@id/logo"
android:text="@string/passenger_name"
android:textColor="@color/gray32"
android:textSize="38dp" />
我有不同的字体,我用在不同的文本视图。
我的资源中有字体
这在Android 8上非常有效。但在6.0.1的Nexus6上。它不会改变我的字体。
有办法解决这个问题吗?
编辑
我制作了一个字体资源:sans_pro
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
android:font="@font/source_sans_pro_regular"
android:fontStyle="normal"
android:fontWeight="400"
app:font="@font/source_sans_pro_regular"
app:fontStyle="normal"
app:fontWeight="400" />
</font-family>
我把它设置在我的文本视图上。
<TextView
android:id="@+id/logo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:fontFamily="@font/sans_pro"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@id/logo"
android:text="@string/passenger_name"
android:textColor="@color/gray32"
android:textSize="38dp" />
但还是不行。
如果我用编程的方法来做的话,它会起作用的。为什么它不能从xml中工作,我是否遗漏了一些东西?
((TextView) base.findViewById(R.id.logo_text)).setTypeface(ResourcesCompat.getFont(getActivity(), R.font.sans_pro_extralight));
正在使用此支持库:
implementation 'com.android.support:design:27.1.1'