您需要为此 activity 使用 Theme.AppCompat 主题(或后代)。 API 16

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

我遇到了与here相同的问题,但我检查了我的代码和xml文件,我只使用了AppCompat。我正在尝试在 api 16 上 运行。我在这里使用它:

<application
    android:allowBackup="true"
    android:icon="@mipmap/main_icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:name=".GoogleImageSearcher"
    android:theme="@style/AppTheme" >

styles.xml

  <!-- Base application theme. -->
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowBackground">@color/background_material_light</item>

</style>

样式-v21.xml

<style name="AppTheme" parent="Base.AppTheme">
    <!-- Customize your theme here. -->
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
   <!-- <item name="android:navigationBarColor">@color/primary_dark</item>-->
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>

</style>

日志

   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:124)
        at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
        at com.dandewine.user.tocleveroad.MainActivity.onCreate(MainActivity.java:39)

我错过了什么地方,有什么建议吗?

试试这个,替换

android:theme="@style/AppTheme" >

来自

 android:theme="@style/Base.AppTheme" >

尝试将最小 api 设置为 16 或使用一些额外的库,例如 android arsena

如果您向应用程序添加了任何不兼容的主题,请检查清单文件(如果 'MainActivity' 是 AppCompatActivity 的 child。它的主题应该继承自 Theme.AppCompat 或来自其中一个 child仁.