【问题标题】:Android 5.0 RuntimeException with AppCompat Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat themeAndroid 5.0 RuntimeException with AppCompat Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme
【发布时间】:2015-01-21 18:44:56
【问题描述】:

我刚刚使用 (hamburger) drawer 创建了 Android 项目,midSDKlevel 设置为 android-8。

我第一次遇到appcompat-v7:21.0.0': No resource found that matches the given name: 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 的确切字符串应该是什么?

【问题讨论】:

  • 检查您的 Android 清单中的主题?
  • 它有android:theme="@style/AppTheme"

标签: android android-support-library android-5.0-lollipop material-design


【解决方案1】:

activity 和 style 之间存在问题。您正在使用 ActionBarActivity 但您有 Th​​eme.Material.Light ,您应该尝试 "Theme.AppCompat" 以适应您的风格

【讨论】:

  • 哪种风格?请写更多信息
  • 我正在使用“Theme.AppCompat.NoActionBar”作为工具栏,您可以使用它。
猜你喜欢
  • 1970-01-01
  • 2021-02-03
  • 2022-12-27
  • 2022-12-02
  • 2022-12-01
  • 2018-04-04
  • 2022-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多