materialButton的使用

1、添加依赖:
    implementation 'com.google.android.material:material:1.3.0'
2、改app主题,使用的主题需继承material中的主题:
    <style name="Theme.PlusDemo" parent="Theme.MaterialComponents.Light.NoActionBar">
3、布局中使用
    <com.google.android.material.button.MaterialButton
        android:id="@+id/button2"
        style="@style/Widget.MaterialComponents.Button.UnelevatedButton"<!-- 去阴影 -->
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:backgroundTint="#987654"<!-- 背景色 -->
        android:gravity="center"
        android:insetTop="0dp"<!-- 去顶部留白 -->
        android:insetBottom="0dp"<!-- 去底部留白 -->
        android:padding="20dp"
        android:text="@string/button"
        android:textSize="20sp"
        app:cornerRadius="40dp"<!-- 圆角 -->
        app:icon="@drawable/clean"<!-- 图标 -->
        app:iconGravity="textEnd"<!-- 图标位置 -->
        app:iconPadding="@dimen/dp_10"<!-- 图标文字距离 -->
        app:iconSize="40dp"<!-- 图标大小 -->
        app:iconTint="#ff0"<!-- 图标着色 -->
        app:iconTintMode="multiply"<!-- 图标着色模式 -->
        app:rippleColor="#B300FF"<!--  -->
        app:strokeColor="#f00"<!-- 描边颜色 -->
        app:strokeWidth="2dp"<!-- 描边宽度 -->
         />
    <com.google.android.material.button.MaterialButtonToggleGroup
        android:layout_width="match_parent"
        android:layout_height="20sp"
        android:orientation="horizontal"
        app:checkedButton="@+id/button2"<!-- 默认选中项 -->
        app:singleSelection="true"<!-- 是否单选 -->
        app:selectionRequired="true"<!-- true:强制至少选中一个 -->
        />

    可以自己写选中,点击状态,也可以尝试一下不同模式的区别
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值