How to change color and font on ListView

The question:

I am trying to change my font(color and size) and the back ground on my ListView. I want to change it with code lines not on xml.
my list view looks like:
the xml:

 <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android=""
android:textSize="18sp" android:text="@string/hello">

and my code is

public class NewsActivity  extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

 // ArrayAdapter listItemAdapter = new ArrayAdapter( this,android.R.layout.simple_list_item_1, v_itemList );

      setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,ynetList));

      View v=getListView() ;

      ListView lv = getListView();

what next? please give me an example base on my code

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You need to create a CustomListAdapter.

public class CustomListAdapter extends ArrayAdapter <String> {

    private Context mContext;
    private int id;
    private List <String>items ;

    public CustomListAdapter(Context context, int textViewResourceId , List<String> list ) 
        super(context, textViewResourceId, list);           
        mContext = context;
        id = textViewResourceId;
        items = list ;

    public View getView(int position, View v, ViewGroup parent)
        View mView = v ;
        if(mView == null){
            LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mView = vi.inflate(id, null);

        TextView text = (TextView) mView.findViewById(;

        if(items.get(position) != null )
            int color = Color.argb( 200, 255, 64, 64 );
                text.setBackgroundColor( color );


        return mView;


The list item looks like this (custom_list.xml):

<?xml version="1.0" encoding="utf-8"?>
    android:textSize="20px" android:paddingTop="10dip" android:paddingBottom="10dip"/>

Use the TextView api’s to decorate your text to your liking

and you will be using it like this

listAdapter = new CustomListAdapter(YourActivity.this , R.layout.custom_list , mList);

Method 2

Create a CustomAdapter and in that you have the getView() so there if you want to change the listview background color use this :


If you want to change the textColor then do this :


and for the textSize :


where ‘v’ is the listview and ‘tv’ is the textview

Method 3

Even better, you do not need to create separate android xml layout for list cell view. You can just use “android.R.layout.simple_list_item_1” if the list only contains textview.

private class ExampleAdapter extends ArrayAdapter<String>{

    public ExampleAdapter(Context context, int textViewResourceId, String[] objects) {
        super(context, textViewResourceId, objects);

    public View getView(int position, View convertView, ViewGroup parent) {

        View view =  super.getView(position, convertView, parent);

        TextView tv = (TextView) view.findViewById(;

        return view;

Method 4

You can select a child like

TextView tv = (TextView)lv.getChildAt(0);

Method 5

If u want to set background of the list then place the image before the < Textview>

< ImageView

and if u want to change color then put color code on above textbox like this


Method 6

If you just need to change some parameters of the View and the default behavior of ArrayAdapter its OK for you:

 import android.content.Context;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;

 public class CustomArrayAdapter<T> extends ArrayAdapter<T> {

    public CustomArrayAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);

            // Here all your customization on the View

        return view;


Method 7

If you want to use a color from colors.xml , experiment

   public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = inflater.inflate(this.rowLayoutID, parent, false);
        TextView title = (TextView) rowView.findViewById(;

You can use too:

private static final int bgColor = 0xAAAAFFFF;
public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = inflater.inflate(this.rowLayoutID, parent, false);

Method 8

use them in Java code like this:

 color = getResources().getColor(R.color.mycolor);

The getResources() method returns the ResourceManager class for the current activity, and getColor() asks the manager to look up a color given a resource ID

Method 9

in android 6.0 you can change the colour of text like below


All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment