简体   繁体   中英

Android 2.3.3 Listview Background Is Gray

So I have a rather annoying issue with a listview. My app was working just fine until the Android 2.3.3 update on my Droid 2. (Still seems to work fine on a Samsung Evo)

There are a few aspects of this issue. 1. The background is always gray in empty slots. 2. The last entry in the list appears to be invisible until it is selected. When selected you can see the black text, but no background. 3. Other/Older entries in the list do show with the correct background color.

I have tried quite a few things, and nothing seems to fix this. Thoughts?

Listview definition

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content" 
 android:gravity="left|center"
 android:layout_width="wrap_content" 
 android:layout_alignParentBottom="true"
 android:paddingLeft="1px">
 <TextView android:text="" 
 android:id="@+id/list_view_text_view"
 android:layout_width="wrap_content" 
 android:textSize="13sp"    
 android:singleLine="false"
 android:layout_height="wrap_content"
 android:layout_marginLeft="1sp">
</TextView>


</LinearLayout>

Main Layout of listview

         <ListView android:id="@+id/ListView01" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:layout_alignRight="@+id/Button06" 
        android:layout_below="@+id/TextView01" 
        android:layout_alignLeft="@+id/TextView01"
        android:layout_marginBottom="2sp"
        android:layout_marginRight="2sp"
        android:layout_marginLeft="2sp"
        android:layout_above="@+id/EditText01" 
        android:transcriptMode="normal"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:gravity="bottom"
 >
 </ListView>

Listveiw Adapter

private class EfficientAdapter extends BaseAdapter {
       private LayoutInflater mInflater;

       public EfficientAdapter(Context context) {
       mInflater = LayoutInflater.from(context);

       }

       public int getCount() {
       return comment_list.size();
       }

       public Object getItem(int position) {
       return position;
       }

       public long getItemId(int position) {
       return position;
       }
       public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder;

       if (convertView == null) {
       convertView = mInflater.inflate(R.layout.listview, null);
       holder = new ViewHolder();
       holder.text = (TextView) convertView
       .findViewById(R.id.list_view_text_view);

       convertView.setTag(holder);
       } else {
       holder = (ViewHolder) convertView.getTag();

       }

       holder.text.setText(comment_list.get(position).toString());

       return convertView;
       }

       class ViewHolder {
       TextView text;
       }
       }

This is the code i use to try and set the background in my main routine.

        list_view_comments.setBackgroundResource(R.color.color_con);
        list_view_comments.setDrawingCacheBackgroundColor(R.color.color_con);
        list_view_comments.setBackgroundColor(R.color.color_con);
        list_view_comments.setCacheColorHint(R.color.color_con);

Your issue is the same as this issue on SO... Listview background is grey on Droid 3

Here is the solution that Motorola gives us as a workaround... http://community.developer.motorola.com/t5/MOTODEV-Blog/Why-Does-My-ListView-Look-Different/ba-p/17462

Basically they (Motorola) are using a customized theme that you must override using attributes like

android:overScrollFooter="@null"

Edit - The link above no longer works for some reason. However, as Kevin said in the comments, the solution will still work.

嗨使用这可能对你有帮助。

list_view_comments.setBackgroundColor(getResources().getColor(R.color.color_con));

How to draw a ListView in OS v2.3 so that the extra space below your last row item displays your specified background instead of the gray default footer background color:

overScrollFooter is unacceptable to most builds.
height="wrap_content" by itself only works if there are no other widgets below your ListView. Removing layout_alignParentBottom="true" can work, but can also damage the screen layout depending on the ListView's relationship with other widgets.

The most straightforward way to reduce the height of your ListView so there is no extra footer space that Motorola OS v2.3 wants to paint gray, is to wrap the ListView in another Layout such as a LinearLayout. Make the LinearLayout whatever size you wish and reduce the height of the internal ListView to "wrap_content" . If you want more explanation and an example, navigate here: List View Footer Background on Android 2.3.3 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM