I'm trying to change font of a TextView to a custom one. Have read this other question and tried instructions as outlined here. The font in question is Roboto Thin, downloaded straight from Android Design and is in ttf.
The code at the main activity class is as follows:
TextView txt = (TextView) findViewById(R.id.hometext);
Typeface font = Typeface.createFromAsset(getAssets(), "Roboto-Thin.ttf");
txt.setTypeface(font);
// "hometext" is the TextView I wish to change font of.
App does not crash when the above 3 lines are commented, which I hope isolates the problem.
Other etc info:
- Android 4.1.2 (API 16)
- testing on Android 4.4
EDIT:
Also tried "fonts/Roboto-Thin.ttf" and "assets/fonts/Roboto-Thin.ttf", both don't work.
01-17 22:38:29.086: D/AndroidRuntime(17774): Shutting down VM
01-17 22:38:29.086: W/dalvikvm(17774): threadid=1: thread exiting with uncaught exception (group=0x415f4ba8)
01-17 22:38:29.106: E/AndroidRuntime(17774): FATAL EXCEPTION: main
01-17 22:38:29.106: E/AndroidRuntime(17774): Process: sp.com, PID: 17774
01-17 22:38:29.106: E/AndroidRuntime(17774): java.lang.RuntimeException: Unable to start activity ComponentInfo{sp.com/sp.com.POSServices}: java.lang.RuntimeException: native typeface cannot be made
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.ActivityThread.access$800(ActivityThread.java:135)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.os.Handler.dispatchMessage(Handler.java:102)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.os.Looper.loop(Looper.java:136)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.ActivityThread.main(ActivityThread.java:5017)
01-17 22:38:29.106: E/AndroidRuntime(17774): at java.lang.reflect.Method.invokeNative(Native Method)
01-17 22:38:29.106: E/AndroidRuntime(17774): at java.lang.reflect.Method.invoke(Method.java:515)
01-17 22:38:29.106: E/AndroidRuntime(17774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-17 22:38:29.106: E/AndroidRuntime(17774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-17 22:38:29.106: E/AndroidRuntime(17774): at dalvik.system.NativeStart.main(Native Method)
01-17 22:38:29.106: E/AndroidRuntime(17774): Caused by: java.lang.RuntimeException: native typeface cannot be made
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.graphics.Typeface.<init>(Typeface.java:175)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.graphics.Typeface.createFromAsset(Typeface.java:149)
01-17 22:38:29.106: E/AndroidRuntime(17774): at sp.com.POSServices.onCreate(POSServices.java:18)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.Activity.performCreate(Activity.java:5231)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-17 22:38:29.106: E/AndroidRuntime(17774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
01-17 22:38:29.106: E/AndroidRuntime(17774): ... 11 more