Search code examples
androidmaterial-componentsmaterial-components-androidandroid-chips

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


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.


Solution

  • 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
        })