Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3615486
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:22:46+00:00 2026-05-18T22:22:46+00:00

I am trying to set the ListView textColor to black, since I am using

  • 0

I am trying to set the ListView textColor to black, since I am using a white background.

Here is my MailActivity

public class MailActivity extends ListActivity {

    String[] listItems = { "Compose", "Inbox", "Drafts", "Sent" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.mails);

        setListAdapter(new ArrayAdapter(this,
                android.R.layout.simple_list_item_1, listItems));

    }
}

and my XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="#FFFFFF">

    <ListView 
        android:id="@android:id/list" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <TextView 
        android:id="@android:id/empty" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="Empty set" 
        android:textColor="#000000" />

</LinearLayout>

I’m getting the background as white, but am not sure where to set the foreground to black. I’ve tried in the xml and looks like it’s not helping.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:22:47+00:00Added an answer on May 18, 2026 at 10:22 pm

    Ok, here are some things that you should be clear about:

    1. The background color you are setting in your xml file is of the activity and not of the ListItems you are trying to define.
    2. Every list item has its own layout file which should be passed or inflated in case you are using complex layout for list item.

    I’ll try to explain this with a code sample:

    ****Lets start with ListItems layout** : save it in your res/layout folder of you Android project with say **list_black_text.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Definig a container for you List Item-->
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:gravity="center_vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <!-- Defining where should text be placed. You set you text color here-->
        <TextView
            android:id="@+id/list_content"
            android:textColor="#000000"
            android:gravity="center"
            android:text="sample"
            android:layout_margin="4dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        />
    </LinearLayout>
    

    Well, a simple layout with a TextView to be precise. You must have an id assigned to TextView in order to use it.

    Now coming to you screen/activity/chief layout, as I said you are defining background to your screen with android:background attribute. I see you have defined a TextView there as well and I suspect you are trying to define content/list item there, which is not at all needed.

    Here’s your edited layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:background="#FFFFFF">
    
        <ListView 
            android:id="@android:id/list" android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
            <!-- REMOVED TEXT VIEW, AND KEEPING BACKGROUND WHITE -->
    </LinearLayout>
    

    And lastly, most importantly, set your adapter.

    setListAdapter(new ArrayAdapter<String>(
                this, R.layout.list_black_text, R.id.list_content, listItems));
    

    Notice the layout resource which we are passing to adapter R.layout.list_black_text, and R.id.list_content which is TextView ID we declared. I have also changed ArrayAdapter to String type since it’s generic.

    I hope this explains everything. Mark my answer accepted if you agree.

    Messy but a good quick fix way
    You can also do this with a quick fix if you do not want to go ahead with complex layout defining etc.

    While instantiating the adapter declare an inner class to do this, here is the code sample:

        ArrayAdapter<String> adapter=new ArrayAdapter<String>(
                this, android.R.layout.simple_list_item_1, listItems){
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View view =super.getView(position, convertView, parent);
    
                TextView textView=(TextView) view.findViewById(android.R.id.text1);
    
                /*YOUR CHOICE OF COLOR*/
                textView.setTextColor(Color.BLUE);
    
                return view;
            }
        };
    
        /*SET THE ADAPTER TO LISTVIEW*/
        setListAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to set different textcolor for different list items of a listview. How
I'm using ListActivity to set up my listview. What I want to do is
Hi I am trying to set focus on an item in a listview. After
I'm trying to make a listview from an arraylist using the tutorial i found
iv been having trouble trying to set a listview from a json object from
I'm trying to populate a listview from another class, but I'm geting this error:
I'm trying to set a Listview under some other Widgets (Buttons, editText, etc). I
I am trying to set the DataTemplate of my ListView.GridView's CellTemplate dynamically at runtime.
I'm trying to set the View for my ListView dynamically: But I get an
I have a ListView with a header, set using ListView.addHeader(...) It appears to work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.