标签: android-chips

如何在android.support.design.chip.Chip中设置文本颜色?

<android.support.design.chip.Chip
     style="@style/Widget.MaterialComponents.Chip.Choice"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_margin="4dp"
     android:checked="true"
     android:padding="4dp"
     android:textAppearance="?android:textAppearanceSmall"
     app:chipBackgroundColor="@color/selector"
     app:chipText="Test"
     app:chipIconEnabled="true"
     app:chipIconSize="20dp" />
Run Code Online (Sandbox Code Playgroud)

在XML中,没有类似的属性:

chipTextColor
Run Code Online (Sandbox Code Playgroud)

以编程方式SpannableString不起作用:

SpannableStringBuilder builder = new SpannableStringBuilder();
String numeric = getString(R.string.patient_list_order_date);
SpannableString whiteSpannable= new SpannableString(numeric);
whiteSpannable.setSpan(new ForegroundColorSpan(Color.WHITE), 0, numeric.length(), 0);
builder.append(whiteSpannable);
chip.setChipText(builder);
Run Code Online (Sandbox Code Playgroud)

java android colors android-chips

2
推荐指数
2
解决办法
3168
查看次数

不要在Android的材料组件芯片上显示选中的图标

编辑:我设法通过在styles.xml中设置以下属性来使其工作,如下所示:

  <android.support.design.chip.Chip
                    android:id="@+id/chipFollowing"
                    style="@style/ChipCustomStyle" ...>
Run Code Online (Sandbox Code Playgroud)

styles.xml

<style name="ChipCustomStyle" parent="Widget.MaterialComponents.Chip.Action">
    <item name="checkedIconEnabled">false</item>
    <item name="checkedIcon">@null</item>
</style>
Run Code Online (Sandbox Code Playgroud)

如果有人遇到相同的WTF,请将其留在这里:)


原始问题:

我不想在芯片上显示选中的图标。我尝试设置

        app:checkedIcon="@null"
        app:checkedIconVisible="false"
Run Code Online (Sandbox Code Playgroud)

都在Chip和ChipGroup元素中。它甚至不会编译:/

当我将其设置在Chip元素上时,我得到:错误:找不到属性'com.companyname.projectname:checkedIconVisible'。

这是我的Chip XML:

            <android.support.design.chip.Chip
                android:id="@+id/chipFollowing"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checkable="true"
                android:clickable="true"
                android:focusable="true"
                android:textAppearance="@style/ChipFilledUncheckedText"
                app:checkedIcon="@null"
                app:checkedIconVisible="false"
                app:chipBackgroundColor="@color/bg_chip_state_list"
                app:chipText="@string/chip_following" />
Run Code Online (Sandbox Code Playgroud)

我正在使用28支持库版本中的材料组件。我是否缺少明显的东西?:/

android material-design android-chips

2
推荐指数
1
解决办法
1543
查看次数

如何修改筹码样式?

我需要使用芯片制作以下 UI

在此处输入图片说明

我已经实现了芯片并使其可检查,但我不知道如何将其样式更改为图片

我更改了笔触颜色和背景颜色以及笔触宽度

所以正常的筹码没有问题,我的问题是检查过的筹码是蓝色的

任何人都可以请教吗?

android material-design android-chips material-components-android

2
推荐指数
2
解决办法
2081
查看次数

芯片组边距和多线

我正在开发一个带有芯片的应用程序。

我有一个带有 TextView 和 ChipGroup 的约束布局。芯片以编程方式添加。

这是布局

...
<com.google.android.material.chip.ChipGroup
    android:id="@+id/chipGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:background="@android:color/holo_red_dark"
    android:gravity="end"
    app:layout_constraintBottom_toTopOf="@+id/chartView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/textView"
    app:layout_constraintTop_toBottomOf="@+id/project3">

</com.google.android.material.chip.ChipGroup>

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="24dp"
    android:text="Pippo"
    android:textColor="@color/greenPositive"
    app:layout_constraintBottom_toTopOf="@+id/chartView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/project3" />
...
Run Code Online (Sandbox Code Playgroud)

该活动显示为屏幕截图(我在芯片组中放置了红色背景以显示该区域)

在此输入图像描述

  • ChipGroup 被限制在 textview 的末尾,但忽略这个限制和边距。
  • 最后,Chip 被截断,但 ChipGroup 最后有 16dp 的余量。
  • 第一行和第二行不与第一行对齐
  • 我将重力末端放在 ChipGroup 中,但芯片已对齐以开始。

如何解决所有这些问题?

android android-layout android-chips

2
推荐指数
1
解决办法
2746
查看次数

如何以编程方式选择 Android 中 ChipGroup 中的默认芯片?

TL;DR - 以编程方式选择作为 Android 中 ChipGroup 子代的默认选择芯片的正确方法是什么?

——

在我的 android 应用程序中,我使用com.google.android.material.chip.Chip样式作为@style/Widget.MaterialComponents.Chip.Choice组件来表示用户可以为给定路线选择的活动选择(想想步行、自行车等)

因为一条路线可以有不同类型的活动,所以我以编程方式将每种类型作为不同的芯片插入到com.google.android.material.chip.ChipGroup. 我还在片段的 onViewCreated() 期间使用以下代码选择默认芯片作为插入列表中的第一个芯片

 private fun setupTypeSelection(types: List<Type>) {
    types.forEach { type ->
        val chip = layoutInflater.inflate(R.layout.chip_type, viewBinding.typeChipGroup, false) as Chip

        chip.tag = type
        /* Init chip text and icon */

        chip.setOnClickListener {
            /* Update selected type */
        }

        if (currentType == null) {
            chip.isSelected = true
            currentType = type
        }

        viewBinding.typeChipGroup.addView(chip)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是 ChipGroup 的布局定义,其中我设置了单选等

chip_group_layout.xml

<com.google.android.material.chip.ChipGroup
      android:id="@+id/type_container"

      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="@dimen/margin_medium" …
Run Code Online (Sandbox Code Playgroud)

android android-layout material-design android-chips

2
推荐指数
1
解决办法
2354
查看次数

在 Android 中以编程方式选择和取消选择 ChipGroup 内的所有芯片

我有一个芯片组,在其中以编程方式添加选择芯片,并且有一个名为“全选”的按钮,用于选择所有芯片(如果选择了其中一些芯片)和“相同的按钮”,用于通过单击取消选择所有芯片。

现在请指导我一些正确的方法,或者如果可以使用芯片组而不是芯片的ArrayList来完成,那就太好了提前感谢:)

android android-studio android-chips material-components-android

1
推荐指数
1
解决办法
4581
查看次数

不推荐使用的android Materialchip.setCloseIconEnabled(true)的替代方案是什么

我正在使用材料android芯片。这里关闭图标不可见。查看一些参考后,我正在使用chip.setCloseIconEnabled(true)但它已被弃用。

final Chip chip=new Chip(MainActivity.this);
        chip.setText(color);
        chip.setCheckable(false);
        chip.setClickable(true);
        chip.setCloseIconEnabled(true);
        chipGroup.addView(chip);
Run Code Online (Sandbox Code Playgroud)

android material-design android-chips

0
推荐指数
1
解决办法
484
查看次数