如何使用android-support-v7-appcompat

来源:互联网 发布:货物进出库软件 编辑:程序博客网 时间:2024/05/16 14:37

天真的以为跟v4一样,把jar包放入自个儿的项目即可,不出各位看官所料,报错了,喜欢看官方的可以看这里 support library setup


当直接把jar包放入,错误信息如下:

11-11 18:11:02.945: W/System.err(9880): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable11-11 18:11:02.946: W/System.err(9880): at android.support.v7.app.DrawerArrowDrawable.<init>(DrawerArrowDrawable.java:64)11-11 18:11:02.946: W/System.err(9880): at android.support.v7.app.ActionBarDrawerToggle$DrawerArrowDrawableToggle.<init>(ActionBarDrawerToggle.java:469)11-11 18:11:02.946: W/System.err(9880): at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:222)11-11 18:11:02.947: W/System.err(9880): at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:150)..........11-11 18:11:02.948: W/System.err(9880): at android.app.Activity.performCreate(Activity.java:5251)11-11 18:11:02.948: W/System.err(9880): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)11-11 18:11:02.949: W/System.err(9880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)11-11 18:11:02.949: W/System.err(9880): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)11-11 18:11:02.949: W/System.err(9880): at android.app.ActivityThread.access$800(ActivityThread.java:138)11-11 18:11:02.949: W/System.err(9880): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)11-11 18:11:02.949: W/System.err(9880): at android.os.Handler.dispatchMessage(Handler.java:102)11-11 18:11:02.950: W/System.err(9880): at android.os.Looper.loop(Looper.java:136)11-11 18:11:02.950: W/System.err(9880): at android.app.ActivityThread.main(ActivityThread.java:5014)11-11 18:11:02.950: W/System.err(9880): at java.lang.reflect.Method.invokeNative(Native Method)11-11 18:11:02.950: W/System.err(9880): at java.lang.reflect.Method.invoke(Method.java:515)11-11 18:11:02.951: W/System.err(9880): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)11-11 18:11:02.951: W/System.err(9880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)11-11 18:11:02.951: W/System.err(9880): at dalvik.system.NativeStart.main(Native Method)11-11 18:11:02.952: W/FlurryAgent(9880): Error logged: uncaught11-11 18:11:02.952: W/FlurryAgent(9880): Ending session11-11 18:11:02.953: W/System.err(9880): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable11-11 18:11:02.953: W/System.err(9880): at android.support.v7.app.DrawerArrowDrawable.<init>(DrawerArrowDrawable.java:64)11-11 18:11:02.954: W/System.err(9880): at android.support.v7.app.ActionBarDrawerToggle$DrawerArrowDrawableToggle.<init>(ActionBarDrawerToggle.java:469)11-11 18:11:02.954: W/System.err(9880): at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:222)11-11 18:11:02.954: W/System.err(9880): at android.support.v7.app.ActionBarDrawerToggle.<init>(ActionBarDrawerToggle.java:150).........11-11 18:11:02.956: W/System.err(9880): at android.app.Activity.performCreate(Activity.java:5251)11-11 18:11:02.956: W/System.err(9880): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)11-11 18:11:02.956: W/System.err(9880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)11-11 18:11:02.956: W/System.err(9880): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)11-11 18:11:02.957: W/System.err(9880): at android.app.ActivityThread.access$800(ActivityThread.java:138)11-11 18:11:02.957: W/System.err(9880): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)11-11 18:11:02.957: W/System.err(9880): at android.os.Handler.dispatchMessage(Handler.java:102)11-11 18:11:02.957: W/System.err(9880): at android.os.Looper.loop(Looper.java:136)11-11 18:11:02.958: W/System.err(9880): at android.app.ActivityThread.main(ActivityThread.java:5014)11-11 18:11:02.958: W/System.err(9880): at java.lang.reflect.Method.invokeNative(Native Method)11-11 18:11:02.958: W/System.err(9880): at java.lang.reflect.Method.invoke(Method.java:515)11-11 18:11:02.959: W/System.err(9880): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)11-11 18:11:02.959: W/System.err(9880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)11-11 18:11:02.959: W/System.err(9880): at dalvik.system.NativeStart.main(Native Method)

其实错误信息中很赤裸裸的告诉咱了,缺style,关键是为什么会缺呢?
java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

其实v7中有大量的style,也就是说简单添加jar包并没有引入style,所以只能以library的形式添加到自个儿的项目中,步骤如下:



选择自己SDK下的sdk/extras/android/support/v7/appcompat,导入项目,记得勾选 

然后在自己的项目中操作如下,注意红框部分:



然后点击绿色部分,添加v4,v7的jar包:



然后:


没记错的话,应该大功告成了,下课~

0 0