我有一個由自定義適配器支持的ListView,可根據其內容動態更改每行的背景顏色。該getView看起來是這樣的:Android:如何讓ListView的背景色顯示在選區後面?
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
Power power = powers.get(position);
if(row == null)
{
row = getLayoutInflater().inflate(android.R.layout.simple_list_item_2, parent, false);
}
TextView text1 = (TextView)row.findViewById(android.R.id.text1);
TextView text2 = (TextView)row.findViewById(android.R.id.text2);
text1.setText(power.name);
text2.setText(power.getAttackLine());
row.setBackgroundColor(0xFF0000FF);
return row;
}
所有每當我從列表中選擇一個項目,工程桃色的,不同之處在於,標準red/orange
只突出顯示了該行的後面,只爲在每一側幾個像素可見它。有沒有辦法讓選擇出現在背景之上?
因爲默認的ListView選擇器沒有透明度,是不是隻會讓整行變成橙色? – 2009-12-03 15:12:11
我曾假設他已經在改變選擇器。但是,你是對的 - 你需要一個具有適當透明度的選擇器9補丁或XML定義的可繪製對象。 – CommonsWare 2009-12-03 16:45:54
哦,太棒了!我目前使用默認選擇器,但我可以更改它很容易。非常感謝! – Ian 2009-12-03 18:42:51