Android 4.2.2上的黑色背景

时间:2013-07-09 18:36:37

标签: android background textview

我在TextView中遇到ListView令人难以置信的问题。 Android 4.2.2上TextView第一行的ListView颜色为黑色。 (Nexus 4)在Android 4.2.1上,它没有颜色。在我的HTC One上一切正常,直到我收到更新到4.2.2。现在前两行的TextView有黑色背景。来自Nexus的第一排黑色screenshot说更多。

适配器代码如下:

public class NotificationsAdapter extends ArrayAdapter<Object> {

private ArrayList<Object> items;
Context context;    
private LayoutInflater mInflater;
Typeface rb;
Typeface bn;
Typeface rr;
Typeface rbc;

public NotificationsAdapter(Context context, int textViewResourceId, ArrayList<Object> items) {
        super(context, textViewResourceId, items);     
        this.context = context;            
        this.items = items; 
        mInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rb = Typeface.createFromAsset(getContext().getAssets(), "Roboto-Bold.ttf");
        bn = Typeface.createFromAsset(getContext().getAssets(), "BebasNeue.otf");
        rr = Typeface.createFromAsset(getContext().getAssets(), "Roboto-Regular.ttf");
        rbc = Typeface.createFromAsset(getContext().getAssets(), "Roboto-BoldCondensed.ttf");
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {     

        int type;
        if(items.get(position).getClass().equals(String.class))
            type = 0;
        else
            type = 1;          

        if(type == 0){
            String m = (String)items.get(position);
            if (m != null) {                
                convertView = mInflater.inflate(R.layout.notification_month_row, null);
                TextView month_date = (TextView)convertView.findViewById(R.id.tw_notification_month);   
                month_date.setTypeface(rb);
                month_date.setText(m);                      
            }
        }
        else{                         
            Notifications o = (Notifications)items.get(position);
            if (o != null) { 
                convertView = mInflater.inflate(R.layout.notification_row, null);
                TextView month_date = (TextView)convertView.findViewById(R.id.tw_notification_date);
                TextView title = (TextView)convertView.findViewById(R.id.tw_notification_title);
                TextView note = (TextView)convertView.findViewById(R.id.tw_notification_description);
                ImageView mark = (ImageView)convertView.findViewById(R.id.iv_notification_marker);
                title.setTypeface(bn);
                title.setText(o.getTitle());                    
                note.setTypeface(rr);
                note.setText(o.getDescription());                       
                month_date.setTypeface(rbc);
                month_date.setText(o.getDate());                        
                if(o.getConfirmed().equals("1")){
                    mark.setVisibility(4);
                }else{
                    mark.setVisibility(0);
                }                                       
            }
        }

        return convertView;
    }

有谁知道为什么会这样?

XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="fill_parent"
android:layout_height="fill_parent"   
android:layout_margin="0dp"
android:paddingTop="0dp"
android:paddingBottom="25dp"    
android:background="@drawable/background_cell_profile"    
 >     


 <RelativeLayout 
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" >
 <TextView 
        android:id="@+id/tw_notification_title"             
        android:layout_toLeftOf="@+id/tw_notification_date"
        android:layout_alignParentLeft="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"             
        android:layout_marginTop="25dp"        
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp"   
        android:lines="1"     
        android:singleLine="true"
        android:ems="3"     
        android:ellipsize="end"         
        android:textSize="27sp"
        android:textColor="#ffffff"
        android:shadowColor="#000000"
        android:shadowDy="-2"
        android:shadowRadius="0.1"
        android:clickable="false" 
        android:focusable="false"/>

 <TextView 
        android:id="@+id/tw_notification_date"
        android:layout_marginTop="25dp"
        android:layout_alignParentRight="true"         
        android:layout_marginLeft="10dp"            
        android:layout_marginRight="10dp"           
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"                             
        android:textSize="20sp"
        android:textColor="#ffffff"
        android:shadowColor="#000000"
        android:shadowDy="-2"
        android:shadowRadius="0.1"
        android:clickable="false" 
        android:focusable="false"/>

 <TextView 
        android:id="@+id/tw_notification_description"
        android:layout_below="@+id/tw_notification_title"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"            
        android:layout_marginLeft="10dp" 
        android:layout_marginTop="10dp" 
        android:layout_marginRight="10dp"                                   
        android:textSize="14sp"
        android:textColor="@color/gray_to_white"
        android:shadowColor="#000000"
        android:shadowDy="-2"
        android:shadowRadius="0.1"
        android:clickable="false" 
        android:focusable="false"/>    
</RelativeLayout>

 <ImageView 
     android:id="@+id/iv_notification_marker"
     android:layout_width="40dp"
     android:layout_height="40dp"
     android:padding="0dp"
     android:layout_marginTop="0dp"
     android:layout_gravity="right|top"
     android:src="@drawable/icon_oznameni_unreadindicator"/>

1 个答案:

答案 0 :(得分:0)

不确定它是否有帮助,但您错误地使用了LayoutInflater:

convertView = mInflater.inflate(R.layout.notification_month_row, null);

应该是:

convertView = mInflater.inflate(R.layout.notification_month_row, parent, false);

使用前者有时会给我带来奇怪的渲染问题。

请参阅this blog post