【Android】使用MaterialButton

如何使用Google的MaterialButton
摘要由CSDN通过智能技术生成

1. 添加依赖包

在app下的build.gradle里添加Google Material Button的依赖包
implementation ‘com.google.android.material:material:1.7.0’
Module的grdle文件
添加后要sync gradle。

2. 修改Theme

在res文件夹下的theme.xml里,把App的主题的父主题改为“Theme.MaterialComponents.Light.NoActionBar”
在这里插入图片描述

3. MaterialButton的继承关系

java.lang.Object
↳android.view.View
↳android.widget.TextView
↳android.widget.Button
↳androidx.appcompat.widget.AppCompatButton
↳com.google.android.material.button.MaterialButton

4. 常用属性

属性 说明
app:backgroundTint 背景颜色
app:backgroundTintMode 颜色模式
app:strokeColor 描边颜色
app:strokeWidth 描边宽度
app:cornerRadius 圆角大小
app:icon 在按钮中设置图标
app:iconSize 图标大小
app:iconGravity 图标显示重心(位置)
app:iconTint 图标颜色
app:iconPadding 图标和文本之间的间距
style=“@style/Widget.MaterialComponents.Button.UnelevatedButton” 去掉按钮的阴影效果

5. 实例

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.material.button.MaterialButton
        android:layout_width="150dp"
        android:layout_height="50dp"
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值