[英]Calligraphy fonts doesn't work from style.xml
嗨,我尝试使用书法
我的活动中有这个:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
我想在这种布局中使用字体(它是片段的布局):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fontPatch="http://schemas.android.com/apk/res-auto"
style="@style/fragmentMainBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/grid_0"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/grid_0"
tools:context=".app.mainscreen.MainActivity"
tools:ignore="MissingPrefix">
<TextView
android:id="@+id/statusTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/fontDexlineProRegular"/>
//...
和我的风格:
<style name="fontDexlineProRegular" parent="android:TextAppearance">
<item name="fontPath">fonts/DexlinePro-Regular.ttf</item>
</style>
这行不通。
但是当我尝试使用它时:字体有效
//...
<TextView
android:id="@+id/statusTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fontPath="fonts/DexlinePro-Regular.ttf"/>
//...
如何从样式设置字体? style.xml有什么问题?
将您的
DexlinePro_Regular.ttf
放入资产文件夹
注意:请使用ttf文件作为底线...
并设置为textview。
TextView statusTv= (TextView) findViewById(R.id.statusTv);
Typeface font = Typeface.createFromAsset(getAssets(), "DexlinePro_Regular.ttf");
statusTv.setTypeface(font);
我添加了这个: CalligraphyConfig.initDefault( ...
及其开始工作:/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.