Android studio 有没有办法在Android Studio上更改textview第一个字母的颜色?

Android studio 有没有办法在Android Studio上更改textview第一个字母的颜色?,android-studio,Android Studio,所以我有一个小小的文本视图 <TextView android:id="@+id/textDescription" android:layout_width="102dp" android:layout_height="34dp" android:layout_marginTop="8dp" android:fontFamily="@font/open_sans_bold" android:te

所以我有一个小小的文本视图

<TextView
        android:id="@+id/textDescription"
        android:layout_width="102dp"
        android:layout_height="34dp"
        android:layout_marginTop="8dp"
        android:fontFamily="@font/open_sans_bold"
        android:text="Red"
        android:textSize="21sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/addclass_photo" />


我只想在android上把字母“R”改为红色:文本:“红色”

有几种方法可以实现这一点

    TextView textView = findViewById(R.id.textDescription);

    String firstChar = "<font color='#EE0000'>R</font>";
    String str = "ed";
    textView.setText(Html.fromHtml(firstChar + str));
    // or
    textView.setText(Html.fromHtml("<font color='#EE0000'>R</font>ed"));
TextView TextView=findViewById(R.id.textDescription);
字符串firstChar=“R”;
字符串str=“ed”;
setText(Html.fromHtml(firstChar+str));
//或
textView.setText(Html.fromHtml(“红色”));
或在科特林:

val textView = findViewById<TextView>(R.id.textDescription)
val firstChar = "<font color='#EE0000'>R</font>"
val str = "ed"
textView.text = Html.fromHtml(firstChar + str)
// or 
textView.text = Html.fromHtml("<font color='#EE0000'>R</font>ed")
val textView=findViewById(R.id.textDescription)
val firstChar=“R”
val str=“ed”
textView.text=Html.fromHtml(firstChar+str)
//或
textView.text=Html.fromHtml(“红色”)
结果:

此问题涉及更改一个单词/子字符串,并包含其他方法: