<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);
So you can use the setChipBackgroundColor(ColorStateList cl) method to set the color of your chip and then you can add an setOnClickListener(new ...) to toggle with selection and non-selection like the following code: yourchip. setOnClickListener(new View.
Android TextView – Text Color. TextView Text Color – To change the color of text in TextView, you can set the color in layout XML file using textColor attribute or change the color dynamically in Kotlin file using setTextColor() method.
In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000" .
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>
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With