向导航抽屉添加向后兼容性

时间:2013-11-11 10:02:20

标签: android navigation-drawer

如何为API 8及更高版本的导航抽屉添加向后兼容性。

logcat的:

11-11 16:12:31.796: E/AndroidRuntime(621): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.MainActivity}: java.lang.ClassNotFoundException: com.example.android.navigationdrawerexample.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-2.apk]
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.os.Looper.loop(Looper.java:123)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.reflect.Method.invokeNative(Native Method)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.reflect.Method.invoke(Method.java:521)
11-11 16:12:31.796: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-11 16:12:31.796: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-11 16:12:31.796: E/AndroidRuntime(621):  at dalvik.system.NativeStart.main(Native Method)
11-11 16:12:31.796: E/AndroidRuntime(621): Caused by: java.lang.ClassNotFoundException: com.example.android.navigationdrawerexample.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-2.apk]
11-11 16:12:31.796: E/AndroidRuntime(621):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-11 16:12:31.796: E/AndroidRuntime(621):  ... 11 more

2 个答案:

答案 0 :(得分:1)

请参阅此链接最适合导航抽屉的向后兼容性

https://github.com/BradleyRL/NavDrawerExampleAppCompat-v7

答案 1 :(得分:0)

  

我使用了actionbarsherlock库来获得向后兼容性:

  • 导入sherlocak导航抽屉。

  • 导入actionbarsherlock。

请参阅this tutorial进行设置。

修改

  

不使用actionbarsherlock库: