我正在尝试在 android 应用程序中更改我的 ActionBar 字体。
在 4.3 设备上运行我的代码时一切正常,但是当我尝试在 2.3.3 设备上运行它时,我的应用程序崩溃了。
这是我用来更改字体的功能:
SpannableString s = new SpannableString("MyActivity");
s.setSpan(new TypefaceSpan(this, "myFont"), 0, s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Update the action bar title with the TypefaceSpan instance
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(s);
由于新的 TypefaceSpan 行,我的应用程序崩溃了。
08-31 19:00:21.359: E/AndroidRuntime(3874): FATAL EXCEPTION: main
08-31 19:00:21.359: E/AndroidRuntime(3874): java.lang.ExceptionInInitializerError
08-31 19:00:21.359: E/AndroidRuntime(3874): at com.blabla.myapp.MainActivity.changeActionBarFont(MainActivity.java:41)
08-31 19:00:21.359: E/AndroidRuntime(3874): at com.blabla.myapp.MainActivity.setupGUIandListeners(MainActivity.java:27)
08-31 19:00:21.359: E/AndroidRuntime(3874): at com.blabla.myapp.MainActivity.onCreate(MainActivity.java:23)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.os.Handler.dispatchMessage(Handler.java:99)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.os.Looper.loop(Looper.java:130)
08-31 19:00:21.359: E/AndroidRuntime(3874): at android.app.ActivityThread.main(ActivityThread.java:3768)
08-31 19:00:21.359: E/AndroidRuntime(3874): at java.lang.reflect.Method.invokeNative(Native Method)
08-31 19:00:21.359: E/AndroidRuntime(3874): at java.lang.reflect.Method.invoke(Method.java:507)
08-31 19:00:21.359: E/AndroidRuntime(3874): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
08-31 19:00:21.359: E/AndroidRuntime(3874): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
08-31 19:00:21.359: E/AndroidRuntime(3874): at dalvik.system.NativeStart.main(Native Method)
08-31 19:00:21.359: E/AndroidRuntime(3874): Caused by: java.lang.NoClassDefFoundError: android.util.LruCache
08-31 19:00:21.359: E/AndroidRuntime(3874): at com.blabla.myapp.TypefaceSpan.<clinit>(TypefaceSpan.java:34)
08-31 19:00:21.359: E/AndroidRuntime(3874): ... 16 more
08-31 19:00:21.369: E/(186): Dumpstate > /data/log/dumpstate_app_error
我在我的 onCreate 函数中设置字体。
任何帮助/想法?
提前致谢