I put some strings in string.xml file as follows.
<string name="text1749">The <font color="#DE0010">book</font> was written by Mr. Martin Vikramasinghe.n<font color="#DE0010">පොත</font> ලිව්වේ මාටින් වික්රමසිංහ විසින්.</string>
The corresponding textview xml code is,
<TextView
android:id="@+id/id155"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/iskpota"
android:gravity="start"
android:justificationMode="inter_word"
android:padding="15dp"
android:textColor="#000000"
android:textSize="20sp"
android:visibility="invisible"
app:autoSizeMaxTextSize="30sp"
app:autoSizeMinTextSize="10sp"
app:autoSizeStepGranularity="2sp"
app:autoSizeTextType="uniform"
android:background="@android:color/transparent"/>
Then I set “text1749” from string.xml file, to textview “@+id/id155” grammatically in activity as follows.
textview.setText(R.string.text1749);
When code runs I cant see the red color. Instead all string(“text1749”) is in black default.
Then tried chatgpt solutions,
TextView testTextView = findViewById(R.id.test_text_view);
String testHtml = "<font color='#FF0000'>Red Text</font> and <font color='#0000FF'>Blue Text</font>";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
testTextView.setText(Html.fromHtml(testHtml, Html.FROM_HTML_MODE_COMPACT));
} else {
testTextView.setText(Html.fromHtml(testHtml));
}
Still no hope.
So If there is a correct way to do this pleas let me know.