带有AppCompat的Android 5.0 RuntimeException原因:java.lang.IllegalStateException:您需要使用Theme.AppCompat主题

保罗·韦斯特

我刚刚使用(汉堡)抽屉创建了Android项目,并将midSDKlevel设置为android-8。

我首先遇到了appcompat-v7:21.0.0':找不到与给定名称匹配的资源:attr'android:actionModeShareDrawable'问题

,然后在Android 5.0模拟器中运行,我得到了RuntimeException

引起原因:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代)。

\app\src\main\res\values-v21\styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Material.Light">
    </style>
</resources>

Android清单

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MyActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

使用AppCompat进行Material Design时应使用什么确切的字符串?

massaimara98

活动和样式之间存在问题。您使用的是ActionBarActivity,但是有Theme.Material.Light,请尝试"Theme.AppCompat"使用样式

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档