我知道如何在Android应用程序中以编程方式设置自定义字体。
是否有一种方法可以为自定义字体(assets)加载typeface,并且Android框架将根据粗体、斜体等使用适当的文件?
例如,现在我正在尝试将Roboto字体设置为某些TextView
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Roboto/Roboto-Regular.ttf");
textView.setTypeface(typeface);
它可以正常工作。但是由于我在xml布局中将TextView
设置为粗体,因此文本并没有加粗。
<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
如何将所有字体加载到一个字体/系列中?