Formatted text appears in a edittext.But the string contains multiple styling .
Is it possible to get the styling used on a particular character in a string , using getT
The first question is how to you set that styling?
If your doing something like Html.fromHtml("hello") calling getTypeFace() will return 0 (TypeFace.NORMAL). For this I would say that you might need to make the parse yourself and create substrings according to the HTML tags you've found.
If you your using the TextView attributes for this - android:textStyle="bold"
You can call directly:
Log.d(TAG, "has typeface=${tv_typeface.typeface.style}")
You can do something like:
//Set an italic style to the word "hello"
val spannableString = SpannableString("hello world")
spannableString.setSpan(StyleSpan(Typeface.ITALIC), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
tv_typeface.text = spannableString
//Get the style italic used
val spannedString = tv_typeface.text as SpannedString
val spans = spannedString.getSpans(0, tv_typeface.length(), StyleSpan::class.java)
for (span in spans) {
Log.d(TAG, "StyleSpan between: ${spannedString.getSpanStart(span)} and ${spannedString.getSpanEnd(span)} with style ${span.style}")
}