我嘗試使用字體類這樣來實現自定義字體上的TextView:字體爲TextView的,EDITTEXT和按鈕給人一種錯誤
package com.royal.bikers;
import android.app.Activity;
import android.os.Bundle;
public class AboutUs extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
TextView aboutUs1 = (TextView) findViewById(R.id.aboutUs1);
TextView aboutUs2 = (TextView) findViewById(R.id.aboutUs2);
TextView aboutUs3 = (TextView) findViewById(R.id.aboutUs3);
TextView aboutUs4 = (TextView) findViewById(R.id.aboutUs4);
TextView aboutUs5 = (TextView) findViewById(R.id.aboutUs5);
TextView aboutUsTitle = (TextView) findViewById(R.id.aboutUsTitle);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Thin.ttf");
aboutUs1.setTypeface(tf);
aboutUs2.setTypeface(tf);
aboutUs3.setTypeface(tf);
aboutUs4.setTypeface(tf);
aboutUs5.setTypeface(tf);
aboutUsTitle.setTypeface(tf);
}
}
,但應用程序的崩潰:
05-09 13:42:13.525: E/AndroidRuntime(24251): FATAL EXCEPTION: main
05-09 13:42:13.525: E/AndroidRuntime(24251): Process: com.royal.bikers, PID: 24251
05-09 13:42:13.525: E/AndroidRuntime(24251): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.royal.bikers/com.royal.bikers.AboutUs}: java.lang.RuntimeException: native typeface cannot be made
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.os.Handler.dispatchMessage(Handler.java:102)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.os.Looper.loop(Looper.java:136)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-09 13:42:13.525: E/AndroidRuntime(24251): at java.lang.reflect.Method.invoke(Native Method)
05-09 13:42:13.525: E/AndroidRuntime(24251): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-09 13:42:13.525: E/AndroidRuntime(24251): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-09 13:42:13.525: E/AndroidRuntime(24251): Caused by: java.lang.RuntimeException: native typeface cannot be made
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.graphics.Typeface.<init>(Typeface.java:175)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.graphics.Typeface.createFromAsset(Typeface.java:149)
05-09 13:42:13.525: E/AndroidRuntime(24251): at com.royal.bikers.AboutUs.onCreate(AboutUs.java:23)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.Activity.performCreate(Activity.java:5231)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-09 13:42:13.525: E/AndroidRuntime(24251): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-09 13:42:13.525: E/AndroidRuntime(24251): ... 9 more
我試過使用另一種字體稱爲Usuzi它工作得很好,但我想將其更改爲Roboto-Thin並且它不適用於它。
這裏是我的AboutUs.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/aboutUs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_bg"
tools:context="com.royal.bikers.AboutUs"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/aboutUsTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="65dp"
android:gravity="center_horizontal"
android:text="@string/aboutUs"
android:textColor="#000"
android:textSize="25sp"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="105dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="110dp"
android:background="#59FFFFFF" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/aboutUs1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:text="@string/aboutUs1"
android:textColor="#000"
android:textSize="20sp" />
<TextView
android:id="@+id/aboutUs2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:text="@string/aboutUs2"
android:textColor="#000"
android:textSize="20sp" />
<TextView
android:id="@+id/aboutUs3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:text="@string/aboutUs3"
android:textColor="#000"
android:textSize="20sp" />
<TextView
android:id="@+id/aboutUs4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:text="@string/aboutUs4"
android:textColor="#000"
android:textSize="20sp" />
<TextView
android:id="@+id/aboutUs5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:text="@string/aboutUs5"
android:textColor="#000"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
這裏的清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.royal.bikers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
<activity
android:name="com.royal.bikers.Splash"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.royal.bikers.Home"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.Login"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.Register"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.AboutUs"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.Search"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.RegisterEvent"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.Event"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.Account"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.royal.bikers.ChangePassword"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
</application>
</manifest>
請給我建議,如果有除創建延伸的TextView作爲CustomTextView類的任何其他方法給定here
確定'中的Roboto-Thin.ttf'可用你的'資產文件夾? –
是的,我在那裏。此方法與** usuzi **字體一起使用,但不適用於任何roboto字體。 – Chipset
將名稱從「Roboto-Thin.ttf」更改爲「Robotothin.ttf」,並嘗試爲此重新卸載應用安裝應用程序 –