【问题标题】:Failed to load AppCompat ActionBar with unknown error?无法加载 AppCompat ActionBar 并出现未知错误?
【发布时间】:2018-06-17 17:16:12
【问题描述】:

build.gradle 文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "io.dume.dume"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso- 
 core:3.0.2'
 }

我刚刚创建了一个新项目,并在 activity_main.xml 上发现了这个错误,我没有改变任何东西。有什么解决办法吗?

【问题讨论】:

标签: android android-studio gradle android-gradle-plugin


【解决方案1】:

我遇到了同样的问题。似乎这是一个 Android Studio 错误。

在您的样式 xml 文件中更改:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

到这里:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

为我工作。

【讨论】:

  • 将紧凑版 28alpha 降级到 27 对我有用
【解决方案2】:

将您的目标 sdk 版本设置为 27 。 将您的 compile sdk 版本设置为 27 。 以及从 28.0.0-alpha3 到 27.1.1 的应用兼容版本。

如果你还想用sdk 28版

只需将 alpha3 替换为 alpha1 即可,无需更改任何其他内容

【讨论】:

    【解决方案3】:

    发生这种情况时这对我有用,我不知道为什么它不适用于 28:

    //use this instead 
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    targetSdkVersion 27
    
    dependencies{
    
    //switch to these
    implementation 'com.android.support:appcompat-v7:27.0.0-alpha'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.0.0'
    
    }
    

    【讨论】:

      【解决方案4】:

      我在 YouTube 上使用 3 种方法修复了这个错误

      【讨论】:

        【解决方案5】:

        这对我有用。

        打开,res --> values --> styles.xml,在这里你会发现这样一行:

        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        

        改成:

        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        

        也就是说,将 DarkActionBar 更改为 NoActionBar

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-11-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多