【问题标题】:Android: Get Chip icon click eventAndroid:获取芯片图标点击事件
【发布时间】:2019-06-24 06:33:04
【问题描述】:

我使用材料组件芯片。在芯片中我们可以获得关闭图标点击和整个芯片点击事件。但是找不到芯片图标点击。

<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.setOnCloseIconClickListener { chipGroup.removeView(chip as View) } 是你想要的这个
  • @AravindV 我想点击编辑图标。带有方形红色标记的那个。
  • 你试过用 ChipDrawableImageSpan 吗?

标签: android android-chips material-components-android


【解决方案1】:

如果您的 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 方法,也不会出现适当的波纹效果。
  • 你是否尝试在 if 块内返回 false?
猜你喜欢
  • 1970-01-01
  • 2010-09-06
  • 1970-01-01
  • 1970-01-01
  • 2020-04-14
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 1970-01-01
相关资源
最近更新 更多