7
<android.support.design.chip.Chip
     style="@style/Widget.MaterialComponents.Chip.Choice"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_margin="4dp"
     android:checked="true"
     android:padding="4dp"
     android:textAppearance="?android:textAppearanceSmall"
     app:chipBackgroundColor="@color/selector"
     app:chipText="Test"
     app:chipIconEnabled="true"
     app:chipIconSize="20dp" />

In XML there is no attribute like:

chipTextColor

Programmatically SpannableString not working:

SpannableStringBuilder builder = new SpannableStringBuilder();
String numeric = getString(R.string.patient_list_order_date);
SpannableString whiteSpannable= new SpannableString(numeric);
whiteSpannable.setSpan(new ForegroundColorSpan(Color.WHITE), 0, numeric.length(), 0);
builder.append(whiteSpannable);
chip.setChipText(builder);
pnuts
  • 58,317
  • 11
  • 87
  • 139

4 Answers4

19

I managed to set the text-color in 28.0.0-alpha3 like this:

chip.setChipText(text);
chip.setTextAppearanceResource(R.style.ChipTextStyle_Selected);

and create a style with these parameters:

<style name="ChipTextStyle_Selected">
    <item name="android:textSize">13sp</item>
    <item name="android:textColor">@color/white</item>
</style>
Adrian Le Roy Devezin
  • 672
  • 1
  • 13
  • 41
hollmannlu
  • 206
  • 1
  • 4
4

You can simply use android:textColor in xml like:

    <com.google.android.material.chip.Chip
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"/>

Or programatically you can use:

val chip = view.findViewById<Chip>(R.id.chip)
chip.setTextColor(Color.WHITE)
Adrian Le Roy Devezin
  • 672
  • 1
  • 13
  • 41
1

In support library version 28 you can use this code for set color to text in chip

android:textColor="#FFFFFF"

and this code for write text in chip

android:text="example"
Reza Esfandiari
  • 838
  • 10
  • 13
0

public class Chip extends AppCompatCheckBox implements ChipDrawable.Delegate

Chips are compact elements that represent an attribute, text, entity, or action. There is no app:chipTextColor attribute right now.

FYI

The Material Design color system can be used to create a color theme that reflects your brand or style.

Read the official guideline about The color system.

NOTE

You can try with ForegroundColorSpan

DEMO

    SpannableString whiteSpannable= new SpannableString(numeric);
    int color = getResources().getColor(R.color.your_color_name);
    ForegroundColorSpan fcs  =new ForegroundColorSpan(color);
    whiteSpannable.setSpan(new 
    ForegroundColorSpan(Color.WHITE),0,numeric.length(), 0);
    builder.append(whiteSpannable);
    chip.setChipText(builder);
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198