为何ListView中唯独不能设置字体颜色?

[img]http://dl.iteye.com/upload/attachment/428784/4de7b93a-3dd2-3154-8ef9-2e14a84ef39b.png[/img]

[code="java"]
public class TradeActivity extends Activity {

ListView listview;
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    setContentView(R.layout.mystock);

    String[] models=new String[]{"aaa","bbb","abc","adc","zzz","xcd"};

    listview=(ListView)findViewById(R.id.listview);
    TradeAdapter adapter=new TradeAdapter(this,models);
    listview.setAdapter(adapter);
}
class TradeAdapter extends BaseAdapter{
    Context context;
    String[] array;
    TradeAdapter(Context context,String[] array){
        this.context=context;
        this.array=array;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return array.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return array[position];
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        if(convertView==null){
            LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView=inflater.inflate(R.layout.row_simple_list_item_2, null);
        }
        TextView textView0=(TextView)convertView.findViewById(R.id.simple_item_0);
        TextView textView1=(TextView)convertView.findViewById(R.id.simple_item_1);

        textView0.setText(array[position]);
        textView0.setTextColor(R.color.red);//不可以设置
        textView1.setTextSize(20);

        textView1.setText(array[position]);
        textView1.setTextSize(20);//可以设置
        return convertView;
    }

}

}
[/code]
row_simple_list_item_2.xml文件
[code="xml"]
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="100px"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_alignParentLeft="true"
/>

<TextView android:id="@+id/simple_item_1"
    android:layout_width="100px"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:layout_toRightOf="@id/simple_item_0"
    />


[/code]
很简单的一个Listview,可为什么大小可以,颜色不可以?设置了颜色的那行居然不显示文字了。

1个回答

ListView 的xml里有个cache color hint属性,你得把前景色设成透明,后面的字体颜色才能显示出来。。。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐