繁体   English   中英

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

[英]Android: Get Chip icon click event

我使用材料组件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" />

芯片图像

如果你的芯片视图有id 芯片

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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM