我在android中編寫簡單的新應用程序,我想將setTypeface用於活動小部件。Android setTypeface無法正常工作
在這下面的代碼,似乎這就是正確的,但我得到這個錯誤控制檯:
1803-1803/com.example.AndroidMultiPage E/AndroidRuntime﹕
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.AndroidMultiPage/
com.example.AndroidMultiPage.MyActivity}:
java.lang.RuntimeException:
native typeface cannot be made
字體路徑:assets/font/BZar.ttf
我的簡單代碼:
package com.example.AndroidMultiPage;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class MyActivity extends Activity {
private Button submit;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface face = Typeface.createFromAsset(getAssets(),
"font/BZar.ttf");
Button submit = (Button) findViewById(R.id.submitButton);
submit.setTypeface(face);
}
嘗試不同的字體。無論出於何種原因,並非所有字體都與Android兼容。 – CommonsWare
http://stackoverflow.com/questions/12766930/native-typeface-cannot-be-made-only-for-some-people – nobalG