Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

(android) How to fill the Chip's area?

enter image description here

I want to know how to fill the background of Chip in ChipGroup.

Looking at the picture, you can see that the background is not full.

It's a round gray area that surrounds the text, not the square part.

The strange thing is that i set the width to be the same in XML.

As far as I can predict, the background size seems to be affected by the size or number of characters.

But what I want is that even though the number of characters is different, the background size is constant.

(Ps. This ChipGroup run on DialogFragment)

Here is XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:Chip="http://schemas.android.com/tools">
    <HorizontalScrollView
        android:id="@+id/horizontal_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@id/routine_list_recycler"
        android:scrollbars="none"
        android:overScrollMode="never">
        <com.google.android.material.chip.ChipGroup
            android:id="@+id/routine_chipgroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            app:chipSpacingHorizontal="10dp"
            app:singleLine="true"
            app:singleSelection="true">
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="A" />
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="BBB" />

            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="CCC" />
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="DDD" />
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="EEE" />
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="FFF" />
            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="GGG" />
        </com.google.android.material.chip.ChipGroup>
    </HorizontalScrollView>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/routine_list_recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/horizontal_scroll" />
</androidx.constraintlayout.widget.ConstraintLayout>
question from:https://stackoverflow.com/questions/65643881/android-how-to-fill-the-chips-area

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have you tried this

android:chipBackgroundColor="?attr.colorPrimary"
  <com.google.android.material.chip.Chip
                android:chipBackgroundColor="?attr.colorPrimary"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="XYZ" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...