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”
android:text=“@string/app_name”
android:textAllCaps=“false” />
- 与常规使用方法一样,但是加了
style
,这个style在未选中的情况下,对背景色设置了透明
。
圆形Button
<com.google.android.material.button.MaterialButton
android:layout_width=“100dp”
android:layout_height=“100dp”
android:layout_marginTop=“20dp”
android:insetTop=“0dp”
android:insetBottom=“0dp”
android:text=“@string/login”
android:textAllCaps=“false”
android:textSize=“20sp”
app:cornerRadius=“999dp”
app:strokeColor=“@color/orange”
app:strokeWidth=“5dp” />
这里为什么来个圆形Button呢,是因为涉及到两个属性
-
android:insetTop
上边距 -
android:insetBottom
下边距
这两个参数默认是6dp
,不设置为0dp的话,就不是一个规则的圆。
关于其他属性的默认参数,可以在xml文件的右上角
,选中Design
面板,选择要查看的View即可。
author:yechaoa
源码分析icon
唯一不足的是MaterialButton
不能像chip
一样给icon
设置事件。
来看看源码中 icon具体是什么实现的:
public void setIcon(@Nullable Drawable icon) {
if (this.icon != icon) {
this.icon = icon;
updateIcon(/* needsIconUpdate = */ true);
}
}
这里比较简单,继续看调用的updateIcon
方法
private void updateIcon(boolean needsIconUpdate) {
// Forced icon update
if (needsIconUpdate) {
resetIconDrawable(isIconStart);
return;
}
…
if (hasIconChanged) {
resetIconDrawable(isIconStart);
}
}
有省略,看关键两段代码都调用了resetIconDrawable
方法,继续
private void resetIconDrawable(boolean isIconStart) {
if (isIconStart) {
TextViewCompat.setCompoundDrawablesRelative(this, icon, null, null, null);
} else {
TextViewCompat.setCompoundDrawablesRelative(this, null, null, icon, null);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
最后
总而言之,Android开发行业变化太快,作为技术人员就要保持终生学习的态度,让学习力成为核心竞争力,所谓“活到老学到老”只有不断的学习,不断的提升自己,才能跟紧行业的步伐,才能不被时代所淘汰。
在这里我分享一份自己收录整理上述技术体系图相关的几十套腾讯、头条、阿里、美团等公司20年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
还有高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
由于篇幅有限,这里以图片的形式给大家展示一部分。
[外链图片转存中…(img-gqam4nAQ-1712612801381)]
[外链图片转存中…(img-Hu7W1fX8-1712612801381)]
[外链图片转存中…(img-JgPgjePI-1712612801381)]
还有高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!