android 引入ActionBar报错Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat t

引入ActionBar很简单,actionbar封装在v7包中,所以我们只要引入v7包就行,然后继承ActionBarActivity,但是运行起来就报错,错误日记如下:

11-08 11:58:07.004: E/AndroidRuntime(8970): FATAL EXCEPTION: main
11-08 11:58:07.004: E/AndroidRuntime(8970): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zhimore.googleplay/com.zhimore.googleplay.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.ActivityThread.access$600(ActivityThread.java:168)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.os.Handler.dispatchMessage(Handler.java:107)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.os.Looper.loop(Looper.java:194)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.ActivityThread.main(ActivityThread.java:5398)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at java.lang.reflect.Method.invoke(Method.java:525)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at dalvik.system.NativeStart.main(Native Method)
11-08 11:58:07.004: E/AndroidRuntime(8970): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at com.zhimore.googleplay.MainActivity.onCreate(MainActivity.java:12)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.Activity.performCreate(Activity.java:5168)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at com.qihoo360.mobilesafe.loader.b.callActivityOnCreate(SourceFile:98)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
11-08 11:58:07.004: E/AndroidRuntime(8970): 	... 11 more

意思是说activity的style要设置为Theme.AppCompat就好了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值