【问题标题】:Error trying to render MaterialButton from Material Components尝试从材质组件渲染 MaterialButton 时出错
【发布时间】:2018-08-24 04:24:23
【问题描述】:

我遵循了入门指南here,此时我不想迁移到androidx,所以我做了:

  • 确保我拥有正确的存储库

  • com.android.support:design:28.0.0-rc01 添加到我的依赖项中,因为入门教程指出如果我不想迁移到 androidx,这是唯一需要的。

  • 确保 compileSdkVersion 是 28 岁

  • 切换到Theme.MaterialComponents.Light.NoActionBar

  • 已下载的 Android P SDK 和源代码(但不是图片上没有的其他任何内容):

  • 确保我使用的是AppCompactAtivity

  • 重建项目

我仍然得到错误:

找不到以下类: - com.google.android.material.button.MaterialButton

我错过了什么?

【问题讨论】:

    标签: android material-components material-components-android


    【解决方案1】:

    您不应使用 com.google.android.material 包,而应使用 com.android.support。 在您的情况下 android.support.design.button.MaterialButton

    【讨论】:

    • 哦,有道理,但现在我放弃并切换到androidx
    【解决方案2】:

    我在使用 com.android.support 和使用 com.google.android.material 的 Android Studio 3.2 候选版本时遇到了这个问题。

    我升级到了 3.3 canary,尽管我现在遇到了其他(不相关的?)问题(运行时膨胀失败等),但该特定问题消失了。

    我找不到任何说明布局编辑器工作所需的 Android Studio 版本的文档。

    【讨论】:

      【解决方案3】:
      1. 确保存储库部分包含 Google 的 Maven 存储库 google()。例如:

        allprojects {
            repositories {
              google()
        
        allprojects {
            repositories {
              google()
              jcenter()
            }
          }
        
      2. 将库添加到依赖项部分:

        implementation 'com.google.android.material:material:1.0.0'
        dependencies {
        
        
        
        
        // ...
            implementation 'com.google.android.material:material:1.0.0'
        // ...
        }
        

      【讨论】:

        猜你喜欢
        • 2020-07-23
        • 1970-01-01
        • 1970-01-01
        • 2020-01-31
        • 1970-01-01
        • 2019-11-02
        • 1970-01-01
        • 1970-01-01
        • 2019-06-02
        相关资源
        最近更新 更多