Android 配置Material Design库及使用MaterialButton

Android 配置Material Design库

1.首先在gradle.build文件中添加依赖

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

添加后的gradle文件如下,多的可删可不删

ependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.android.support:design:29.0.2'
}

2.更换AndroidManifest文件中的Theme,也就是value/style中的AppTheme属性,如果不修改这个,使用的组件就只有最基本的效果,比如MaterialButton就没有水波纹的效果

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

3.在需要使用Material组件的layout文件中添加

xmlns:app="http://schemas.android.com/apk/res-auto"

如果有的话就不用加了

4.最后给出一个MaterialButton的代码,如果能跑起来并切有水波纹效果就说明配置成功了

    <com.google.android.material.button.MaterialButton
        android:layout_width="200dp"
        android:layout_height="60dp"
        android:gravity="center"
        android:text="MaterialButton"
        android:textColor="#ffffffff"
        android:textSize="24sp"
        app:backgroundTint="#FFA54C" />

5.配置完以后,如果写代码没有自动补全什么的,可以试着Build 一> Rebuild Project一下

猜你喜欢

转载自blog.csdn.net/qq_17282141/article/details/105622969