ChipGroup in android

Những ai biết về Chip có lẽ sẽ không mấy bỡ ngỡ về ChipGroup.

Step 1: Create layout follow code below
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Chip group single choose" />

<com.google.android.material.chip.ChipGroup
android:id="@+id/categoryChipsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical"
app:chipSpacing="5dp"
app:itemSpacing="5dp"
app:singleLine="false"
app:singleSelection="true">

<com.google.android.material.chip.Chip
android:id="@+id/chip"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="Crop image"
android:textColor="@android:color/white"
app:checkedIcon="@drawable/check"
app:chipBackgroundColor="#ff8400"
app:chipEndPadding="8dp"
app:chipIconTint="@android:color/white"
app:chipStartPadding="8dp"
app:textEndPadding="5dp"
app:textStartPadding="5dp" />

<com.google.android.material.chip.Chip
android:id="@+id/chip2"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="Blur image"
android:textColor="@android:color/white"
app:checkedIcon="@drawable/check"
app:chipBackgroundColor="#ff8400"
app:chipEndPadding="8dp"
app:chipIconTint="@android:color/white"
app:chipStartPadding="8dp"
app:textEndPadding="5dp"
app:textStartPadding="5dp" />

<com.google.android.material.chip.Chip
android:id="@+id/chip3"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="Reduce image"
android:textColor="@android:color/white"
app:checkedIcon="@drawable/check"
app:chipBackgroundColor="#ff8400"
app:chipEndPadding="8dp"
app:chipIconTint="@android:color/white"
app:chipStartPadding="8dp"
app:textEndPadding="5dp"
app:textStartPadding="5dp" />
</com.google.android.material.chip.ChipGroup>

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="Chip group multiple choose" />

<com.google.android.material.chip.ChipGroup
android:id="@+id/categoryChipsViewimg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical"
app:chipSpacing="5dp"
app:itemSpacing="5dp"
app:singleLine="false"
app:singleSelection="false">

<com.google.android.material.chip.Chip
android:id="@+id/chip4"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="Groups cloud"
android:textColor="@android:color/white"
app:checkedIcon="@drawable/check"
app:chipBackgroundColor="#994444"
app:chipEndPadding="8dp"
app:chipIconTint="@android:color/white"
app:chipStartPadding="8dp"
app:textEndPadding="5dp"
app:textStartPadding="5dp" />

<com.google.android.material.chip.Chip
android:id="@+id/chip5"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="Mockup"
android:textColor="@android:color/white"
app:checkedIcon="@drawable/check"
app:chipBackgroundColor="#994444"
app:chipEndPadding="8dp"
app:chipIconTint="@android:color/white"
app:chipStartPadding="8dp"
app:textEndPadding="5dp"
app:textStartPadding="5dp" />

<com.google.android.material.chip.Chip
android:id="@+id/chip6"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="File cloud"
android:textColor="@android:color/white"
app:checkedIcon="@drawable/check"
app:chipBackgroundColor="#994444"
app:chipEndPadding="8dp"
app:chipIconTint="@android:color/white"
app:chipStartPadding="8dp"
app:textEndPadding="5dp"
app:textStartPadding="5dp" />
</com.google.android.material.chip.ChipGroup>

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Step 2: Processing in code java file, please read that link

Step 3: Result   

Đăng nhận xét

Mới hơn Cũ hơn