简体   繁体   中英

Android: Get Chip icon click event

I use material component Chip. In chip we can get close icon click and whole chip click event. But Not able to find chip icon click.

<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" />

芯片图像

If your Chip view has 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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