【问题标题】:how to fix material button error in android studio?如何修复android studio中的材质按钮错误?
【发布时间】:2018-10-14 17:34:46
【问题描述】:

我试图在我的 xml 设计中使用材料按钮,但我发现了一个错误。 缺课
找不到 android.support.design.button.MaterialButton 类

我该如何解决这个错误? 我的 xml 和依赖项已附加

这是我的 xml 代码

<android.support.design.button.MaterialButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/login"
            android:text="Login"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp" />

依赖

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

}

【问题讨论】:

    标签: android xml android-studio


    【解决方案1】:

    您使用的是旧版本的库。

    要使用 Material 组件,您需要在 Android Studio 3.2 或更高版本中使用 Refactor 中的 Migrate to Androidx 选项。

    并使用这个库

    implementation 'com.google.android.material:material:1.0.0'

    或者,如果您想继续使用支持库,则需要将库更新到 v28.0.0

    更多内容可以参考这个链接:Material Components Getting Started

    不要在您的应用中同时使用 com.android.support 和 com.google.android.material 依赖项。

    将您的库升级到 28.0.0:

    在您的应用 gradle 文件中,将您的 compileSdkVersiontargetSdkVersion 设置为 28

    并将您的支持库编号更改为 28.0.0,例如

    implementation 'com.android.support:design:28.0.0'
    

    【讨论】:

    • 如何将库升级到 v28.0.0?
    • 更新了我对此查询的回答。确保您使用的是更新的 Android Studio,即 Android Studio v3.2.1 是最新的。
    • 我使用的是 android 2.3.3,因为在 3.2.1 的更新版本中 android.support.design.widget.TextInputLayout 无法正常工作,我该怎么办?
    • 我目前使用的是 3.2.1,TextInputLayout 在这方面也能正常工作。
    • 那么请检查我之前提出的这个问题并告诉我解决方案。 stackoverflow.com/questions/52735405/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 2015-08-14
    • 2018-09-08
    • 1970-01-01
    • 2020-07-02
    相关资源
    最近更新 更多