Android MaterialButton使用详解,告别shape、selector

本文介绍了MaterialButton的基本用法,包括其在MaterialDesign规范下的封装优势,以及如何设置图标、圆角和描边等样式。同时,分享了一份包含Android学习资料、架构视频、面试文档等内容的资源,旨在帮助开发者提升技能和应对面试。
摘要由CSDN通过智能技术生成

在这里插入图片描述

前言

=============================================================

先来看一下MaterialButton是什么

在这里插入图片描述

由上图可以看到MaterialButton也没有什么神秘的,不过是Button的一个子类而已,但是经过谷歌的封装之后,在符合Material Design的基础上,使用起来更加方便了,且容易实现预期效果。

使用

=============================================================

引入material包

implementation ‘com.google.android.material:material:1.2.1’

常规

在这里插入图片描述

<com.google.android.material.button.MaterialButton

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“@string/app_name”

android:textAllCaps=“false” />

  • 与Button使用无异,textAllCaps是取消全部大小写。

图标

在这里插入图片描述

<com.google.android.material.button.MaterialButton

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“20dp”

android:text=“@string/app_name”

android:textAllCaps=“false”

app:icon=“@mipmap/ic_launcher” />

  • app:icon属性指定图标。

圆角

在这里插入图片描述

<com.google.android.material.button.MaterialButton

android:id=“@+id/btn”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“20dp”

android:text=“@string/app_name”

android:textAllCaps=“false”

app:cornerRadius=“25dp”

app:icon=“@mipmap/ic_launcher”

app:iconGravity=“end” />

  • app:cornerRadius属性指定圆角大小。

Button描边

在这里插入图片描述

<com.google.android.material.button.MaterialButton

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“20dp”

android:text=“@string/app_name”

android:textAllCaps=“false”

app:cornerRadius=“25dp”

app:strokeColor=“@color/black”

app:strokeWidth=“3dp” />

  • app:strokeColor 描边颜色

  • app:strokeWidth 描边宽度

文字描边

在这里插入图片描述

<com.google.android.material.button.MaterialButton

style=“@style/Widget.MaterialComponents.Button.OutlinedButton”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“20dp”

android:text=“@string/app_name”

android:textAllCaps=“false”

app:cornerRadius=“5dp”

app:rippleColor=“@color/red”

app:strokeColor=“@color/red”

app:strokeWidth=“3dp” />

  • 与上面不同的是,这里用了style,区别在于上面的是常规Button状态下的描边,这个是文字Button状态下的描边。

  • app:rippleColor 点击波纹颜色

文字按钮

在这里插入图片描述

<com.google.android.material.button.MaterialButton

style=“@style/Widget.MaterialComponents.Button.TextButton”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“20dp”

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

这里我就分享一份资料,希望可以帮助到大家提升进阶。

内容包含:Android学习PDF+架构视频+面试文档+源码笔记高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 这几块的内容。分享给大家,非常适合近期有面试和想在技术道路上继续精进的朋友。

如果你有需要的话,可以点击Android学习PDF+架构视频+面试文档+源码笔记获取免费领取方式

喜欢本文的话,不妨给我点个小赞、评论区留言或者转发支持一下呗~

份资料,希望可以帮助到大家提升进阶。

内容包含:Android学习PDF+架构视频+面试文档+源码笔记高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 这几块的内容。分享给大家,非常适合近期有面试和想在技术道路上继续精进的朋友。

如果你有需要的话,可以点击Android学习PDF+架构视频+面试文档+源码笔记获取免费领取方式

喜欢本文的话,不妨给我点个小赞、评论区留言或者转发支持一下呗~

img

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值