自定义样式的复选框(材料标签)适用于Android Studio。

huangapple go评论118阅读模式
英文:

Custom styled checkbox (Material Chips) for android studio

问题

  1. 我想在 Android 中创建如下所示的芯片:
  2. [![复选框样式][1]][1]
  3. [1]: https://i.stack.imgur.com/EtdbD.png
  4. 是否可以在 Android Studio 中实现?
  5. 如果可以,如何使用 XML 实现?
  6. 尝试创建此复选框,但想知道如何添加类似上面截图的主题:
  7. <CheckBox android:id="@+id/checkBox"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_marginTop="40dp"
  11. android:text="Gold"
  12. app:layout_constraintBottom_toBottomOf="parent"
  13. app:layout_constraintEnd_toEndOf="parent"
  14. app:layout_constraintHorizontal_bias="0.113"
  15. app:layout_constraintStart_toStartOf="parent"
  16. app:layout_constraintTop_toBottomOf="@+id/textView"
  17. app:layout_constraintVertical_bias="0.008" />
英文:

I would like to create chips in android like shown below:

自定义样式的复选框(材料标签)适用于Android Studio。

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:

  1. &lt;CheckBox android:id=&quot;@+id/checkBox&quot; android:layout_width=&quot;wrap_content&quot;
  2. android:layout_height=&quot;wrap_content&quot; android:layout_marginTop=&quot;40dp&quot;
  3. android:text=&quot;Gold&quot; app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
  4. app:layout_constraintEnd_toEndOf=&quot;parent&quot;
  5. app:layout_constraintHorizontal_bias=&quot;0.113&quot;
  6. app:layout_constraintStart_toStartOf=&quot;parent&quot;
  7. app:layout_constraintTop_toBottomOf=&quot;@+id/textView&quot;
  8. app:layout_constraintVertical_bias=&quot;0.008&quot; /&gt;

答案1

得分: 2

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

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

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

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

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

在此处查看完整的入门指南这里

英文:

The view components you refer to are called chips.
By using the material design library, you can use chips like this:

  1. &lt;com.google.android.material.chip.Chip
  2. android:layout_width=&quot;wrap_content&quot;
  3. android:layout_height=&quot;wrap_content&quot;
  4. android:text=&quot;@string/hello_world&quot;/&gt;

Source: https://material.io/develop/android/components/chip/

In order to use the material design library, you need to:

  1. Add the dependency to your app module's gradle file
  1. implementation &#39;com.google.android.material:material:1.0.0&#39;
  1. Use AppCompatActivity
  2. 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.

huangapple
  • 本文由 发表于 2020年4月6日 21:58:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/61061519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定