Android Studio的自定义样式复选框(材料芯片)

问题描述 投票:-2回答:1

我想在android中创建芯片,如下所示:

CheckBox style

是否可以使用android studio这样做?如果是这样,我该如何使用XML?

尝试创建此CheckBox,但想知道如何添加主题,如上面的屏幕截图:

<CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" 
  android:layout_height="wrap_content" android:layout_marginTop="40dp" 
  android:text="Gold" app:layout_constraintBottom_toBottomOf="parent" 
  app:layout_constraintEnd_toEndOf="parent" 
  app:layout_constraintHorizontal_bias="0.113" 
  app:layout_constraintStart_toStartOf="parent" 
  app:layout_constraintTop_toBottomOf="@+id/textView" 
  app:layout_constraintVertical_bias="0.008" />
java android android-checkbox material-components-android android-chips
1个回答
2
投票

您引用的视图组件称为chips。通过使用材料设计库,您可以使用像这样的芯片:

<com.google.android.material.chip.Chip
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"/>

来源:https://material.io/develop/android/components/chip/

为了使用材料设计库,您需要:

  1. 将依赖项添加到应用模块的gradle文件中
implementation 'com.google.android.material:material:1.0.0'
  1. 使用AppCompatActivity
  2. 在应用程序中,使用其中一种设计主题作为您的父主题。例如。 Theme.MaterialComponents.DayNight

查看完整的入门指南here。>>

© www.soinside.com 2019 - 2024. All rights reserved.