开发者

Android - set ListView background

I want to set ListView background color white and it have white background set, but main problem is that I want to set the ArrayList color black.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/profilelivin"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orient开发者_StackOverflow中文版ation="vertical">

    <TableRow
        android:id="@+id/row1213"
        android:layout_width="fill_parent"
        android:layout_height="55px"
        android:background="@drawable/backg"
        android:orientation="vertical">

        <TextView
            android:id="@+id/livin123"
            android:layout_width="245px"
            android:layout_height="fill_parent"
            android:layout_marginLeft="5px"
            android:paddingTop="10dp"
            android:text="vvvvvvvvvv"
            android:textColor="#000000"></TextView>

        <Button
            android:id="@+id/livdonable"
            android:layout_width="69px"
            android:layout_height="40px"
            android:layout_marginTop="5px"
            android:text="vvvvv"></Button>

    </TableRow>

    <TableLayout
        android:id="@+id/livintablpart"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ListView
            android:id="@+id/ListView01"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"></ListView>
    </TableLayout>
</TableLayout>

How can I set ArrayList value color to black?

lView = (ListView) findViewById(R.id.ListView01);
lView.invalidateViews();

lView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, arr));
lView.setTextFilterEnabled(true);
lView.setCacheColorHint(Color.BLACK);
lView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);


You can either style the layout you have defined in android.R.layout.simple_list_item_single_choice

Or make your own layout and use that instead with whatever color you want.


android:background="#ffffff" > change it to android:background="#000000" >


public class ListAct extends ListActivity {
   TextView selection;
   private static final String[] items={"Apple", "Bat", "Cat",
           "Dog", "Eagle",
           "Fan", "Goat", "Hut", "Iron", "Jackel",
           "Kitten", "Lion", "Mat", "Nut"};
   
   @Override
   public void onCreate(Bundle icicle) {
     super.onCreate(icicle);
     setContentView(R.layout.main);
     setListAdapter(new IconicAdapter());
     selection=(TextView)findViewById(R.id.selection);
   }
   
   public void onListItemClick(ListView parent, View v,
                               int position, long id) {
     selection.setText(items[position]);
   }

Create the list adapter

//list of array strings which will serve  as LIST ITEMS
 
  class IconicAdapter extends ArrayAdapter<String> {
     IconicAdapter() {
       super(ListAct.this, R.layout.row, R.id.label, items);
     }
     
     public View getView(int position, View convertView,
                         ViewGroup parent) {
       View row=super.getView(position, convertView, parent);
       ImageView icon=(ImageView)row.findViewById(R.id.icon);
         
       if (items[position].length()>4) {
         icon.setImageResource(R.drawable.remove);
       }
       else {
         icon.setImageResource(R.drawable.Yes);
       }
       
       return(row);
     }
   }
 }

main.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" >
   <TextView
     android:id="@+id/selection"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"/>
   <ListView
     android:id="@android:id/list"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:drawSelectorOnTop="false"
     />
 </LinearLayout>
  
 row.xml
 
<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
 >
   <ImageView
     android:id="@+id/icon"
     android:padding="2dip"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/yes"
   />
   <TextView
     android:id="@+id/label"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textSize="40sp"
   />
 </LinearLayout>
  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜