代码之家  ›  专栏  ›  技术社区  ›  Aanal Shah

安卓:获取芯片图标点击事件

  •  1
  • Aanal Shah  · 技术社区  · 6 年前

    <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

    0 回复  |  直到 6 年前
        1
  •  3
  •   Dmytro Batyuk    6 年前

    炸薯条 :

    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
    }