Android Chip view doesn't capitalize letters with android:textAllCaps="true"

Viewed 410

I've got Chip inflated dynamically and added to ChipGroup:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip 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"
    style="@style/Widget.MaterialComponents.Chip.Choice"
    android:layout_width="wrap_content"
    android:layout_height="24dp"
    android:checkable="false"
    android:clickable="true"
    android:ellipsize="end"
    android:focusable="true"
    android:letterSpacing="0.02"
    android:maxLines="1"
    android:textColor="#515968"
    android:textSize="12sp"
    android:textAllCaps="true"
    app:chipBackgroundColor="#00000000"
    app:chipCornerRadius="3dp"
    app:chipStrokeColor="#a6aab1"
    app:chipStrokeWidth="1dp"/>

which does not capitalize letters via android:textAllCaps="true"

Non-capitalized

Chip inherits from TextView so it should work. https://material.io/components/chips/#action-chips doesn't show capitalized example, although I don't see any reason why not.

What a mistake could I made? I don't see any.

2 Answers

It turned out, that textAllCaps does work, but... programatically.

viewHolder.someProviders.addView((LayoutInflater.from(viewHolder.someProviders.context)
    .inflate(R.layout.name_of_layout, viewHolder.someProviders, false) as Chip)
    .apply {
        text = provider.name
        isAllCaps = true
    })

You can use the android:textAppearance attribute:

<com.google.android.material.chip.Chip
    android:textAppearance="@style/textAllCaps"
    android:text="AllCaps"
    .../>

with:

  <style name="textAllCaps" parent="@style/TextAppearance.MaterialComponents.Body2">
    <item name="android:textAllCaps">true</item>
  </style>

enter image description here

Note: This requires a minimum of version 1.2.0-alpha03

Related