Android 配置Material Design库

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

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

1

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

ependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.0.2'

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

}

1

2

3

4

5

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

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

1

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

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

1

如果有的话就不用加了

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一下

————————————————

版权声明:本文为博主「Alrey_」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。