【问题标题】:Error inflating class android.support.v7.widget.Toolbar.!膨胀类 android.support.v7.widget.Toolbar 时出错。!
【发布时间】:2017-05-28 10:31:18
【问题描述】:

我看到其他有关 Error inflating class android.support.v7.widget.Toolbar 的问题并尝试了一些解决方案,例如,项目清理和重建、无效缓存和重新启动以及 appcompat 库版本下降,但没有任何效果。

  • gradle(我用的是Cordova,并不是所有代码都来自gradle)

    buildscript {
    repositories {
    mavenCentral()
    jcenter()
    maven {
        url 'https://dl.bintray.com/tonylee/maven/'
    }
    }
    
    // Switch the Android Gradle plugin version requirement depending on the
    // installed version of Gradle. This dependency is documented at
    // http://tools.android.com/tech-docs/new-build-system/version-compatibility
    // and https://issues.apache.org/jira/browse/CB-8143
    dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
     }
    }
    
    
     dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
      // SUB-PROJECT DEPENDENCIES START
    debugCompile(project(path: "CordovaLib", configuration: "debug"))
       releaseCompile(project(path: "CordovaLib", configuration: "release"))
    // SUB-PROJECT DEPENDENCIES END
    provided 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:recyclerview-v7:21.0.3'
    compile 'com.fpang:adsync2:5.2.2'
    
    }
    
  • 广告.java

    setContentView(R.layout.activity_main);
    
  • activity_main.xml 中的工具栏

>

  <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    <TextView
        android:id="@+id/as2_sdk_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="21sp"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:text="@string/app_name"/>
</android.support.v7.widget.Toolbar>

-styles.xml

<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

谁知道这个错误请帮助我。

【问题讨论】:

  • 请从 logcat 发布您的错误堆栈。这是你完整的activity_main.xml 吗?因为它没有容器布局。
  • xml 中的工具栏在哪里
  • 不知道为什么没有附上所有的代码。我现在编辑。
  • 也发布你的 gradle..

标签: android


【解决方案1】:
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    ***android:background="?attr/colorPrimary"***

所有材料设计元素都需要删除,因为工具栏不允许为 API 19 及更低版本定义任何材料相关元素。

【讨论】:

    【解决方案2】:

    这只是 gradle 依赖的问题,你可以同时添加并检查。

    compile 'com.android.support:appcompat-v7:24.1.0'
    compile 'com.android.support:design:24.1.0'
    

    【讨论】:

    • 你的 compile sdk 版本是多少?
    • 请将此依赖项添加到您的应用程序 gradle 中,而不是添加到工作区 gradle 中。
    • 您需要在项目应用级别添加依赖项。
    • 对不起,我不知道什么是 app gradle 和 workspace gradle。在 Gradle 脚本中,我有 build.gradle(Module: CordovaLib)、cordova.gradle(Module: CordovaLib)、build.gradle(Module:android)、gradle-wrapper.properties、proguard-rules.pro、setting.gradle、local .properties
    • 你的应用名称是什么?
    【解决方案3】:

    尝试添加设计库

    compile 'com.android.support:design:23.3.0'
    

    【讨论】:

      【解决方案4】:

      请添加依赖compile 'com.android.support:appcompat-v7:24.0.0'

      【讨论】:

      • 当然,我添加了这段代码。编译'com.android.support:appcompat-v7:21.0.3' 编译'com.android.support:recyclerview-v7:21.0.3'
      猜你喜欢
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多