Search code examples
androidandroid-layouttextviewtextcolor

Change text color of a predefined layout


I searched everywhere but I cannot find a solution for this simple question: I'm using a predefined layout R.layout.simple_list_item_1 but I cannot find the way to modify the text color of the TextViews inside it.


Solution

  • If you don't want to use your own XML layout, you can get the TextView from that layout and set the color on that. The ID of the TextView in R.layout.simple_list_item_1 is android.R.id.text1 (see the source for that layout).

    TextView tv = (TextView) findViewById(android.R.id.text1);
    tv.setTextColor(getColor(R.color.new_text_color);