【问题标题】:how to make material chips with dropdown list如何使用下拉列表制作材料芯片
【发布时间】:2021-05-30 16:38:12
【问题描述】:

我正在尝试设计材料芯片,每个材料都是一个下拉列表 what I am trying to do 有什么办法可以激活这个

【问题讨论】:

  • 您可以添加更多输入吗?根据您的问题,我知道您想创建一个具有圆形边框的下拉菜单,对吗?
  • @skypore 您可以使用app:closeIcon 添加下拉箭头,然后以编程方式扩展弹出菜单。
  • @NeelDsouza ex。 listof("car1","car1","car1")
  • 欢迎来到stackoverflow,看看How do I ask a good question?

标签: android material-design android-textinputlayout android-chips


【解决方案1】:

您可以使用以下组件来代替 Chip 组件:

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/textField"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
            app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.rounded50"
        >

        <AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
        />

    </com.google.android.material.textfield.TextInputLayout>

与:

<style name="ShapeAppearanceOverlay.App.rounded50" parent="">
    <item name="cornerSize">50%</item>
</style>

最后:

    val items = listOf("Material", "Design", "Components", "Android")
    val adapter = ArrayAdapter(this, R.layout.list_item, items)
    (textField.editText as? AutoCompleteTextView)?.setAdapter(adapter)

【讨论】:

    【解决方案2】:
       chip.setOnCloseIconClickListener {
                val menu = PopupMenu(requireContext(), it)
                menu.getMenu().add("AGIL")
                menu.getMenu().add("AGILarasan")
                menu.getMenu().add("Arasan")
                menu.show()
            }
          <com.google.android.material.chip.Chip
                android:id="@+id/chip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_marginStart="4dp"
                android:layout_marginTop="16dp"
                android:text="@string/email_address"
                android:textColor="@color/greyish_brown"
                app:checkedIconEnabled="false"
                app:chipBackgroundColor="@color/white"
                app:chipStrokeColor="@color/light_grey_level_1"
                app:chipStrokeWidth="1dp"
                app:closeIcon="@drawable/ic_arrow_dropdown"
                app:closeIconEnabled="true"
                app:closeIconSize="10dp"
                app:closeIconTint="@color/greyish_brown"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多