Android:获取芯片图标点击事件

7

我使用材料组件Chip。在Chip中,我们可以获取关闭图标单击和整个Chip单击事件。但找不到Chip图标单击事件。

<com.google.android.material.chip.Chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textColor="@color/chip_text_color"
app:checkedIconEnabled="false"
app:chipBackgroundColor="@color/chip_background"
app:chipIcon="@drawable/ic_pencil_edit_button"
app:chipIconSize="15dp"
app:chipIconTint="@color/chip_text_color"
app:chipStrokeColor="@color/colorPrimary"
app:chipStrokeWidth="1dp"
app:closeIconTint="@color/colorYellow"
app:iconStartPadding="@dimen/spacing_tiny" />

Chip image


chip.setOnCloseIconClickListener { chipGroup.removeView(chip as View) } 这是您想要的吗? - Aravind V
@AravindV 我想要点击编辑图标,就是那个带有红色方块标记的。 - Aanal Shah
你尝试过使用_ChipDrawable_和_ImageSpan_吗? - Piyush
1个回答

4
如果您的Chip视图具有id chip
findViewById<Chip>(R.id.chip).setOnTouchListener { v, event ->
    if (v is Chip) {
        if (event.x <= v.totalPaddingLeft) {
            //HANDLE CLICK TO THE ICON
        }
        return@setOnTouchListener true
    }
    return@setOnTouchListener false
}

但是,当使用触摸方法时,setOnCloseIcon方法不会被调用,并且适当的涟漪效果也不会出现。 - Deepak Rajput
你尝试在if块内使用return false了吗? - Dmytro Batyuk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接