簡體   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