我知道如何在Android应用程序中以编程方式设置自定义字体。 有什么方法可以为自定义字体(资产)加载字体,Android框架将使用基于粗体,斜体等的正确文件吗?
例如现在我正在尝试将Roboto字体设置为某些TextView
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto/Roboto-Regular.ttf");
textView.setTypeface(typeface);
可以。 但是由于我将xml布局内的TextView设置为粗体,因此文本未加粗
android:id="@+id/my_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp"
android:textStyle="bold"
android:gravity="center"
android:text="@string/my_text"
android:textColor="@color/my_foreground"
android:textSize="24dp" />
如何正确从资产加载字体,这将起作用?
textView.setTypeface(typeface, Typeface.BOLD);
在我的资产目录中,只有一个“字体家族”
Roboto-Black.ttf
Roboto-BlackItalic.ttf
Roboto-Bold.ttf
Roboto-BoldCondensed.ttf
Roboto-BoldCondensedItalic.ttf
Roboto-BoldItalic.ttf
Roboto-Condensed.ttf
Roboto-CondensedItalic.ttf
Roboto-Italic.ttf
Roboto-Light.ttf
Roboto-LightItalic.ttf
Roboto-Medium.ttf
Roboto-MediumItalic.ttf
Roboto-Regular.ttf
Roboto-Thin.ttf
Roboto-ThinItalic.ttf
如何在一个字体/家族中加载所有这些字体?