LoginSignup
0
0

More than 3 years have passed since last update.

MaterialComponentのChipの背景色を透明にする方法

Posted at

タイトルのとおりです。軽く詰まったので残します。

↑のテキストを見ると、app:chipBackgroundColorというAttributeが存在するのがわかります。そこにtransparentを設定してみましょう。

<style name="ChipStyle" parent="Widget.MaterialComponents.Chip.Action">
    <item name="chipStrokeColor">?colorOnPrimary</item>
    <item name="android:textColor">?colorOnPrimary</item>
    <item name="chipBackgroundColor">@android:color/transparent</item>
</style>

chip_trimmed1.png

こうなる。why。

https://github.com/material-components/material-components-android/issues/367
↑のIssueを発見。
別途、chipSurfaceColorを設定する必要があるみたい。

<style name="MatchedAffinityChip" parent="Widget.MaterialComponents.Chip.Action">
    <item name="chipCornerRadius">32dp</item>
    <item name="chipStrokeWidth">1dp</item>
    <item name="chipStrokeColor">?colorOnPrimary</item>
    <item name="android:textColor">?colorOnPrimary</item>
    <item name="chipBackgroundColor">@android:color/transparent</item>
    <item name="chipSurfaceColor">@android:color/transparent</item>
</style>

chip_trimmed2.png

こうなる。

よかったですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0