You need to use a Theme.AppCompat theme (or descendant) with this activity

E/AndroidRuntime:
          FATAL EXCEPTION: main
          Process: com.katherine.du.everydaystudy, PID: 8337
          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.katherine.du.everydaystudy/com.katherine.du.everydaystudy.up20170807.RecyclerViewDemoActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2688)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2749)
          at android.app.ActivityThread.-wrap12(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:160)
          at android.app.ActivityThread.main(ActivityThread.java:6202)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
          Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
          at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
          at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
          at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
          at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
          at com.katherine.du.everydaystudy.up20170807.RecyclerViewDemoActivity.onCreate(RecyclerViewDemoActivity.java:25)
          at android.app.Activity.performCreate(Activity.java:6736)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2641)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2749) 
          at android.app.ActivityThread.-wrap12(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:160) 
          at android.app.ActivityThread.main(ActivityThread.java:6202) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

重点在于:You need to use a Theme.AppCompat theme (or descendant) with this activity.

即RecyclerViewDemoActivity需要Theme.AppCompat的主题。


原因:RecyclerViewDemoActivity继承了AppCompatActivity

解决方法:

第一步:在styles.xml文件中自定义MyAppCompactTheme,其parent只要是Theme.AppCompat的主题就行

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="MyAppCompactTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" type="text/css">
        <item name="android:windowIsTranslucent">true</item>
    </style>

</resources>
第二步:在AndroidManifest.xml文件中,将RecyclerViewDemoActivity的主题设置为MyAppCompactTheme即可

        <activity
            android:name=".up20170807.RecyclerViewDemoActivity"
            android:theme="@style/MyAppCompactTheme">

        </activity>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值