When using the ForegroundColorSpan on a piece of text instead of changing the text color it will underline it when the cursor is on top of it. This happens on my (Physical) Pixel 3 running Android 9 (Pie) and on a (Physical) Pixel 1 also running Android 9 (Pie).
However, when I run it on a (Virtual) FWVGA running Android 7.1.1 (Nougat) it turns up as expected.
I have looked all around but I'm not able to find anything in regards to this (possibly because Android 9 is relatively new?)
MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val editText = findViewById<EditText>(R.id.codeView)
var ss: SpannableStringBuilder = SpannableStringBuilder("I'm RED and I'm GREEN now")
//val testing123: Spanned = Html.fromHtml("<u><font color='#2eb6f0'>Blue I Hope</font></u>")
val fcsRed: ForegroundColorSpan = ForegroundColorSpan(Color.RED)
val fcsGreen: ForegroundColorSpan = ForegroundColorSpan(Color.GREEN)
ss.run {
setSpan(fcsRed, 3, 7, 0)
setSpan(fcsGreen, 16, 21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
editText.setText(ss)
}
}
activity_main.xml -> codeView
<EditText
android:id="@+id/codeView"
android:text = ""
android:layout_width="362dp"
android:layout_height="503dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:gravity="top|left"
android:inputType="textMultiLine"
android:lines="40"
android:maxLines="20000"
android:minLines="1"
android:scrollbars="vertical|horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.956" />