2013-11-15 37 views
1

什么似乎是我的编码问题?为什么字体不会改变?我已经在assets/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); 


    } 
} 

回答

3

我觉得你的字体路径应该是

String fontPath = "fonts/FaceYourFears.ttf"; 

你有c重新管理资产内的其他资产文件夹?

0

您不能打印您加载到控制台的TypeFace吗?有可能这条路是不正确的,它不应该包含“资产/”,以我的愚见。