-5

I wonder what are all the types of '✔️' characters available on Android (for a TextView)

Nota : I need to be able to change their color (I just saw that it is impossible to change the color for some of them)

Thanks !

toto_tata
  • 14,526
  • 27
  • 108
  • 198
  • Please take a moment to review the following how-to resources: [How to Ask](https://stackoverflow.com/help/how-to-ask) and [How to create complete examples](https://stackoverflow.com/help/mcve). You did not add any code. – Boken Mar 29 '19 at 09:42
  • Some font with a check mark symbol `\u2713`. Such a symbol can then be colored. You need to do rich text. – Joop Eggen Mar 29 '19 at 09:44

1 Answers1

2

You can:

Set text and color in XML:

All of the chars in TextView will have same color - your char (✔️) also. You can extract your char to strings.xml to reuse it in few places.

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:gravity="center"
    android:text="✔"
    android:textColor="#f0f"
    android:textSize="100sp" />

Char


Set text programatically

Char from the (Java) code

TextView textView = findViewById(R.id.text_view);
textView.setText("\u2713");

But color (#0F0) was set in XML:

<TextView
    android:id="@+id/text_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:gravity="center"
    android:textColor="#0F0"
    android:textSize="100sp" />

XML


Using SpannableString

So you can change color only the part of the string.

String first = "stack";
String second = "overflow";
SpannableString spannable = new SpannableString(first + "\u2713" + second);

ForegroundColorSpan color = new ForegroundColorSpan(ContextCompat.getColor(this, android.R.color.holo_red_dark));

spannable.setSpan(
        color,
        first.length(),
        first.length() + 1,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = findViewById(R.id.text_view);
textView.setText(spannable);

In XML there is only empty TextView:

<TextView
    android:id="@+id/text_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:gravity="center"
    android:textColor="#00F"
    android:textSize="50sp" />

There are many post how to use SpannableString mechanism:

spannable

Boken
  • 4,825
  • 10
  • 32
  • 42