0
How can I colorize, left-aligned, right-aligned, bold, or italicize text when we take text from a database?
Please help me 🙏.
3 Antworten
+ 6
I think you want to style the text views in run time, of course not by XML, you can use spannable.
//Retrieving text from database
String spaned=cursor.getString(0);
//Simple example of coloring(in blue)
Spannable styling =new spannable(spaned);
styling.setSpan(new ForegroundColorSpan(Color.BLUE), 0, word.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//Setting text
yourTextView.setText(styling);
You can find all other information from official sites or other resources.
+ 4
abas biglari yes, In this part of the code.
//Apply styling only from 0 to 5th index of the string.
styling.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE).
+ 2
Thanks for your answer, is this method also used to style part of the text?
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~