|
42 | 42 | import android.graphics.drawable.RippleDrawable; |
43 | 43 | import android.graphics.drawable.ShapeDrawable; |
44 | 44 | import android.graphics.drawable.shapes.OvalShape; |
| 45 | +import android.os.Build.VERSION; |
45 | 46 | import android.os.Build.VERSION_CODES; |
46 | 47 | import androidx.appcompat.content.res.AppCompatResources; |
47 | 48 | import android.text.TextUtils; |
@@ -358,6 +359,14 @@ private void loadFromAttributes( |
358 | 359 | float textSize = a.getDimension( |
359 | 360 | R.styleable.Chip_android_textSize, textAppearance.getTextSize()); |
360 | 361 | textAppearance.setTextSize(textSize); |
| 362 | + |
| 363 | + if (VERSION.SDK_INT < VERSION_CODES.M) { |
| 364 | + // This is necessary to work around a bug that doesn't support themed color referenced in |
| 365 | + // ColorStateList for API level < 23. |
| 366 | + textAppearance.setTextColor( |
| 367 | + MaterialResources.getColorStateList(context, a, R.styleable.Chip_android_textColor)); |
| 368 | + } |
| 369 | + |
361 | 370 | setTextAppearance(textAppearance); |
362 | 371 |
|
363 | 372 | int ellipsize = a.getInt(R.styleable.Chip_android_ellipsize, 0); |
@@ -1381,6 +1390,18 @@ public void setTextSize(@Dimension float size) { |
1381 | 1390 | } |
1382 | 1391 | } |
1383 | 1392 |
|
| 1393 | + public void setTextColor(@ColorInt int color) { |
| 1394 | + setTextColor(ColorStateList.valueOf(color)); |
| 1395 | + } |
| 1396 | + |
| 1397 | + public void setTextColor(@Nullable ColorStateList color) { |
| 1398 | + TextAppearance textAppearance = getTextAppearance(); |
| 1399 | + if (textAppearance != null) { |
| 1400 | + textAppearance.setTextColor(color); |
| 1401 | + invalidateSelf(); |
| 1402 | + } |
| 1403 | + } |
| 1404 | + |
1384 | 1405 | /** Delegate interface to be implemented by Views that own a ChipDrawable. */ |
1385 | 1406 | public interface Delegate { |
1386 | 1407 |
|
|
0 commit comments