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 !
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 !
You can:
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 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" />
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: