=============================================================
先来看一下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移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
这里我就分享一份资料,希望可以帮助到大家提升进阶。
内容包含:Android学习PDF+架构视频+面试文档+源码笔记,高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 这几块的内容。分享给大家,非常适合近期有面试和想在技术道路上继续精进的朋友。
如果你有需要的话,可以点击Android学习PDF+架构视频+面试文档+源码笔记获取免费领取方式
喜欢本文的话,不妨给我点个小赞、评论区留言或者转发支持一下呗~
份资料,希望可以帮助到大家提升进阶。
内容包含:Android学习PDF+架构视频+面试文档+源码笔记,高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 这几块的内容。分享给大家,非常适合近期有面试和想在技术道路上继续精进的朋友。
如果你有需要的话,可以点击Android学习PDF+架构视频+面试文档+源码笔记获取免费领取方式
喜欢本文的话,不妨给我点个小赞、评论区留言或者转发支持一下呗~