Skip to content

Commit e3be6b0

Browse files
committed
Support setting textAllCaps in textAppearance xml, switch from calling setSingleLine to setLines(1) so the transformation methods don't replace each other.
android:textAllCaps="true" in the layout xml is being ignored because: 1) A known issue where Chip only reads from its textappearance. However, even after creating a custom textappearance that sets textAllCaps to true, I'm observing an odd behavior: if I comment out the setSingleLine method call in the constructor, then the text becomes all caps. If I comment setSingleLine back in and call setAllCaps, then the text becomes capitalized and single line. I think it's related to two different transformation methods being applied. The one inside setsingleline clobbers the one set by setAllCaps. TextView's constructor applies the singleLine transformation before applying text appearance attributes https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java#L1570-L1609 https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java#L10232 2) The library implementation of TextAppearance reads from "textAllCaps" instead of "android:textAllCaps". https://github.com/material-components/material-components-android/blob/11c57abbd6b11829f49bbeafee4153e5442b2725/lib/java/com/google/android/material/resources/TextAppearance.java#L96 However, if you call Chip#setTextAppearance(@StyleRes int id) which passes it the super method, then "android:textAllCaps" needs to be set because "textAllCaps" is ignored ::sigh:: PiperOrigin-RevId: 283621202
1 parent acd10e6 commit e3be6b0

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • lib/java/com/google/android/material/chip

lib/java/com/google/android/material/chip/Chip.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ public Chip(Context context, AttributeSet attrs, int defStyleAttr) {
226226

227227
// Chip text should not extend to more than 1 line.
228228
if (!chipDrawable.shouldDrawText()) {
229-
setSingleLine();
229+
setLines(1);
230+
setHorizontallyScrolling(true);
230231
}
231232
// Chip text should be vertically center aligned and start aligned.
232233
// Final horizontal text origin is set during the onDraw call via canvas translation.

0 commit comments

Comments
 (0)