2

i want to add a multicolor (maybe html) text to a clickable android listview.

For example: test Is that possible?

4
  • Can you elaborate your question? Commented May 26, 2013 at 12:46
  • in my app i have to display some text which is in multible colors, so i have {green}aaasd{red}sada... And I want to display this text in a listview, i can´t take a normal view because i need each element to be clickable on its own Commented May 26, 2013 at 12:48
  • 1
    You would need a custom Adapter for that. Not possible with the default one. Commented May 26, 2013 at 12:51
  • Yes, but which element should i use for it? Commented May 26, 2013 at 12:52

2 Answers 2

3

Yes it is possible.

Use The Spannable API.

A tuto explain you in details how to do it: http://blog.stylingandroid.com/archives/177

Just some code for understand:

TextView textView = (TextView)findViewById( R.id.TextView );
Spannable spannable = (Spannable)textView.getText();
StyleSpan boldSpan = new StyleSpan( Typeface.BOLD );
spannable.setSpan( boldSpan, 41, 52, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
Sign up to request clarification or add additional context in comments.

Comments

0

It is also possible to use HTML directly quite easily. Here is an example with color, small text and bold text:

String styledText = "<font color='#666666'>grey text</font><small>small text</small><b>bold text</b>";
exampleEditText.setText(Html.fromHtml(styledText));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.