0

How can I colorize, left-aligned, right-aligned, bold, or italicize text when we take text from a database?

Please help me 🙏.

24th Nov 2020, 10:08 AM
abas biglari
abas biglari - avatar
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.
24th Nov 2020, 10:42 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 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).
24th Nov 2020, 12:57 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 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]~~
24th Nov 2020, 12:21 PM
abas biglari
abas biglari - avatar