android - 字体不会改变

标签 android fonts

我的编码有什么问题吗?为什么字体不改变?我已经将字体导入到 asset/fonts 文件夹下。这样我将 xml 和 java 文件附加在一起

XML 文件

<TextView
  android:id="@+id/txt_level1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentTop="true"
  android:layout_centerHorizontal="true"
  android:text="@string/level1"
  android:textSize="@dimen/txtSize"
  android:typeface="sans" />

JAVA文件

package com.example.basichelloworld;

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
import android.graphics.Typeface;

public class Level_1 extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_level_1);

    //Font path
    String fontPath = "assets/fonts/FaceYourFears.ttf";

    //Text view label
    TextView text = (TextView) findViewById(R.id.txt_level1);

    // Loading Font Face
    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);

    // Applying font
    text.setTypeface(tf);


    }
}

最佳答案

我认为你的字体路径应该是

  String fontPath = "fonts/FaceYourFears.ttf";

您是否在 Assets 中创建了另一个 Assets 文件夹?

关于android - 字体不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20004613/

相关文章:

java - 安卓/Java : How to use Tor-Onion-Proxy-Library?

使用来自 jni 的 openGL ES 时的 java glSurfaceView 与 Native-Activity

android - 在谷歌地图上显示很多需要地理编码的位置?

wpf - 使用 Century 代替 Century Gothic 停止 WPF

android - recyclerview 页脚点击加载图片

android - 单击android通知图标不会触发广播接收器

html - CSS 规则可减小当前元素下方所有元素的字体大小

objective-c - 自定义 UIFont 为零

c# - Windows 窗体应用程序中的 UI 控件重叠和字体问题

android - android中的SearchView自定义字体