i want to put large text inside textView. The text has multiple section with multiple colours. i have seen Html.fromHtml() function and also know how to use setSpan(). But any of these not work for me. In my case i dont know the id of text View at runtime. As i am inflating different Views at runtime each View has many textViews. It will be开发者_StackOverflow社区 better if i can find a way to set styles in strings.
Please some one help me out i have spend so much time here.
you can set id of text view weather the view is find by inflater
when you get text view using inflater then you can set id of that particular text view and you can set textSize() and other attributes
This method creating spannables directly with the attributes you need will work.
Basically you can set colors like this, given a TextView
called text
:
String greeting = "Hello World!"
SpannableString str = SpannableString.valueOf(greeting);
str.setSpan(new ForegroundColorSpan(0xffffffff), 0, greeting.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
str.setSpan(new BackgroundColorSpan(0xff0099ff), 0, greeting.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
text.append(str);
精彩评论