簡體   English   中英

書法字體在style.xml中不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM