0

I have a default ListView from android say android.R.layout.simple_list_item_1.In which ListView having the background color black and text of the list is white.

Now i have changed the background color of the ListView to White. So the text poputating on the listView are also of white color by default. That's why the data of the ListView are not visible.

The text which are populating on the ListView is the arraylist. So where I set the color of the text of ListView?? I want to change the Text color populated on the ListView.

Can anybody tell whether it is possible without custom ListView.

chiranjib
  • 5,288
  • 8
  • 53
  • 82
Narendra Pal
  • 6,474
  • 13
  • 49
  • 85

4 Answers4

8

Answer by @Archie.bpgc is right. Go Through This Link that will help you understand what is to be Done.

Let me try to explain:

here is your list adapter :

String Values [] = {"value 1","Value 2"......}
YourlistAdapter = new ArrayAdapter  
      (this, R.layout.listlayout, R.id.listTextView,Values);
YourListView.setAdapter( listAdapter );`

And R.layout.listlayout :

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

<TextView
    android:id="@+id/listTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="your_color"
    android:text="TextView" />

Now i hope you understood.
R.layout.listlayout is your layout for list view.
listTextView is the id of the text view inside the lay out on which your text is to be written.
Values are the string array of the content you want to write on list view

Haresh Chaudhary
  • 4,390
  • 1
  • 34
  • 57
grv_9098
  • 465
  • 5
  • 16
  • Here I got the android.R.id.text1,which is used in adapter. but still not getting that how to attach it with the ListView. Is it a part of custom ListView?? – Narendra Pal Jul 31 '12 at 06:39
  • 1
    http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context, int, int) look to the link here resource is the layout that you selected for the listview and textViewResourceId is the id of the textview inside the layout you selected for the list view. Isted of using the default android.R.layout.simple_list_item_1 make your own layout and inside that take a text view for which you can set textcolor. am i understood ? – grv_9098 Jul 31 '12 at 07:13
2

You might be using this:

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

then change android.R.layout.simple_list_item_1 to some other layout which you define like R.layout.myListItem

and in that myListItem just have a TextView whose android:TextColor="@color/black"

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
-1

Kotlin

val adapter: ArrayAdapter = object: ArrayAdapter(this, android.R.layout.simple_list_item_1, listOfItems) {

override fun getView(position: Int, covertView: View, parent: ViewGroup): View {

val view = super.getView(position, convertView, parent) val text = view.findViewById(R.id.text1) text.setTextColor(ContextCompat.getColor(applicationContext, android.R.color.white))

return View

}

cthoughtz
  • 1
  • 1
-2

set the listview text color like this

ListView android:textColor=""

Newts
  • 1,354
  • 14
  • 23