英文:
Custom styled checkbox (Material Chips) for android studio
问题
我想在 Android 中创建如下所示的芯片:
[![复选框样式][1]][1]
  [1]: https://i.stack.imgur.com/EtdbD.png
是否可以在 Android Studio 中实现?
如果可以,如何使用 XML 实现?
尝试创建此复选框,但想知道如何添加类似上面截图的主题:
<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" />
英文:
I would like to create chips in android like shown below:
Is it possible to do so with android studio?
If so, how can I do it with XML?
Tried creating this CheckBox but want to know how to add theme like the above screenshot:
<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" />
答案1
得分: 2
视图组件称为芯片。
通过使用材料设计库,您可以像这样使用芯片:
<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/
要使用材料设计库,您需要:
- 将依赖项添加到您的应用程序模块的gradle文件中
 
implementation 'com.google.android.material:material:1.0.0'
- 使用AppCompatActivity
 - 在应用程序中将材料设计主题之一用作父主题。例如 
Theme.MaterialComponents.DayNight 
在此处查看完整的入门指南这里。
英文:
The view components you refer to are called chips.
By using the material design library, you can use chips like this:
<com.google.android.material.chip.Chip
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"/>
Source: https://material.io/develop/android/components/chip/
In order to use the material design library, you need to:
- Add the dependency to your app module's gradle file
 
implementation 'com.google.android.material:material:1.0.0'
- Use AppCompatActivity
 - Use one of the material desing themes as your parent theme in the app. E.g. 
Theme.MaterialComponents.DayNight 
Check out the full getting-started guide here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论