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.
Ok, here are some things that you should be clear about:
I’ll try to explain this with a code sample:
****Lets start with ListItems layout** : save it in your
res/layoutfolder of you Android project with say **list_black_text.xmlWell, a simple layout with a
TextViewto 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:backgroundattribute. 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:
And lastly, most importantly, set your adapter.
Notice the layout resource which we are passing to adapter
R.layout.list_black_text, andR.id.list_contentwhich 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: