Android---Chip

       

 

 Chip

        Chip 代表一个小块中的复杂实体,如联系人。它是一个圆形按钮,由一个标签,一个可选的芯片图标和一个可选的关闭图标组成。如果 Chip 可检查,则可以点击或切换Chip 。

    \bullet style="@style/Widget.MaterialComponents.Chip.Action": 默认样式,是一个普通标签,点击后没有任何特殊效果。

    \bullet style="@style/Widget.MaterialComponents.Chip.Entry": 默认一直末尾展示删除按钮;点击后前面展示选中图标,有选中状态,通常可以作为 chipDrawable 使用,比如在填选邮件收件人时可以使用;

    \bullet style="@style/Widget.MaterialComponents.Chip.Filter" 初始状态下,不展示前后图标,点击后会展示前面选中的图标,并且具有选中状态,通常应用在 ChipGroup 中;

    \bullet style="@style/Widget.MaterialComponents.Chip.Choice" 具有选中效果,前后没有图标,点击后有选中颜色变化效果。

 

Chip 基本属性:

类别属性名称具体作用
Shapeapp:chipCornerRadius圆角半径
Sizeapp:chipMinHeight最小高度
Backgroundapp:chipBackgroudColor背景颜色
Borderapp:chipStrokeColor边线颜色
Borderapp:chipStrokeWidth边线宽度
Rippleapp:rippleColor水波纹颜色
Labelandroid:text文本内容
Labelandroi:textAppearance字体样式
Labelandroid:textColor修改文本颜色
Chip Iconapp:chipIconVisible前面图标是否显示
Chip Iconapp:chipIconSizechip中文字前面的图标
Chip Iconapp:chipIconTint文字前面的图标着色
Close Iconapp:closeIconVisiblechip中文字后面关闭按钮是否可见
Close Iconapp:closeIconchip中文字后面的关闭图标
Close Iconapp:closeIconSize文字后面的关闭图标的大小
Close Iconapp:closeIconTInt文字后面的着色
Checkableapp:checkable是否可以被选中
Checked Iconapp:checkedIconVisible选中状态的图标是否可见
Checked Iconapp:checkedIcon选中状态的图标
Motionapp:showMotionSepc动效?
Motionapp:hiheMotoinSpec动效?
Paddingsapp:chipStartPadingchip左边距
Paddingsapp:chipEndPadingchip右边距
Paddingsapp:iconStartPadingchipIcon的左边距
Paddingsapp:iconEndPadingchipIcon的右边距
Paddingsapp:textStartPading文本左边距
Paddingsapp:textEndPading文本右边距
Paddingsapp:CloseIconStartPading关闭按钮的左边距
Paddingsapp:closeIconEndPading关闭按钮的右边距

ChipGroup 

        Chip 可以被放置在 ChipGroup 中,可以实现流逝布局(以前只能通过自定义 view 实现)。该组件合 RadioGroup 很相似,都是用来管理多个子 View 的,可以控制内部子 View 的布局方式。默认情况下,里面的 Chip 是横向多行排列的,每行的最后一个 Chip 控件如果放不下的时候就会自动换行,符合流式布局的规则。

    ChipGroup 基本属性:

    \bullet app:checkedChip: 设置初始默认选中的 chip;

   \bullet app:chipSpacing: 设置 Chip 间的间距,如果有 app:chipSpacingHorizontal 或者 app:chipSpacingVertical 属性,chipSpacing 属性会被覆盖;

   \bullet app:chipSpacingHorizontal: 设置 Chip 之间的水平间距,优先级高于 app:chipSpacing;

   \bullet app:chipSpacingVertiacl: 设置 Chip 之间的垂直间距,优先级高于 app:chipSpacing;

   \bullet app:singleLing: 设置是否开启单行模式;

   \bullet app:singleSelection: 设置是否开启单选模式,默认是多选。

xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.google.android.material.chip.Chip
            android:id="@+id/chip0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="还我星星"/>

        <com.google.android.material.chip.Chip
            android:id="@+id/chip1"
            style="@style/Widget.MaterialComponents.Chip.Entry"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="别偷我的猪"/>

        <com.google.android.material.chip.Chip
            android:id="@+id/chip2"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="一块硬币"/>

        <com.google.android.material.chip.Chip
            android:id="@+id/chip3"
            style="@style/Widget.MaterialComponents.Chip.Choice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="HLLXY"/>
        <com.google.android.material.chip.Chip
            android:id="@+id/chip4"
            style="@style/Widget.MaterialComponents.Chip.Action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="HLLWY"/>

        <com.google.android.material.chip.ChipGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:chipSpacingHorizontal="25dp"
            app:checkedChip="@+id/first"
            app:selectionRequired="true"
            app:singleSelection="true">

            <com.google.android.material.chip.Chip
                android:id="@+id/first"
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="还我星星1"/>
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="还我星星2"/>
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="还我星星3"/>
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="还我星星4"/>
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="还我星星5"/>
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="还我星星6"/>

        </com.google.android.material.chip.ChipGroup>


    </LinearLayout>


</androidx.core.widget.NestedScrollView>

 参考博客:芝麻粒儿 的CSDN

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

别偷我的猪_09

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值