0

I am looking to add formatted text to a ListView (I would like the text to be the color #33B5E5). This is what I tried so far:

ArrayList myarraylist;
String mystring = "Value I want to add"
myarraylist.add(mystring);
//other functions to set the arraylist

My question is, how would I change the color of mystring? Is it possible to set the text color of a string?

  • 1
    Do it in customized list adapter – Glenn Jun 13 '14 at 02:26
  • check the answer in this its pretty much the same http://stackoverflow.com/questions/4533440/android-listview-text-color – JRowan Jun 13 '14 at 02:32
  • @JRowan Read the question carefully I'm trying to make only some text in the ListView formatted, your link is about making the whole ListView formatted. Read before you comment. – user3728164 Jun 13 '14 at 15:20

3 Answers3

0

I think you are looking for this:

myTextView.setTextColor(getResources().getColor(android.R.color.orange.black));
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
0

You can use ArrayAdapter, and create a List<SpannableString>, SpannableString is implementation of CharSequence, so it can behaviors like CharSequence.

the code below is to create a MAGENTA color text.

msp = new SpannableString("Hello I am colo Magenta"); 
msp.setSpan(new ForegroundColorSpan(Color.MAGENTA), 12, 15, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  
John Chen
  • 304
  • 3
  • 8
0

Add fontcolor to your string...

ArrayList<String> myarraylist = new ArrayList<String>();
        String mystring = "<font color='#33B5E5'>Value I want to add</font>";
        myarraylist.add(mystring);

add it to textview...

((TextView)findViewById(R.id.tvTime)).setText(Html.fromHtml(myarraylist.get(0)), TextView.BufferType.SPANNABLE);
Aritra
  • 436
  • 2
  • 6