我以爲我成功地創建了一個條帶化的Android ListView,其中列表項的背景顏色交替出現。當我使用Theme.Holo.Light作爲我的應用程序主題(在Manifest中)時,它完美地工作。 但是,當我爲自己的應用程序定義自定義主題並使用自定義背景色時,條紋消失了,取而代之的是單個背景在我的主題中定義的顏色。 爲什麼我的自定義主題的背景顏色不能被getView()中的setBackgroundColor()重寫?我該如何解決這個問題?謝謝!爲什麼setBackgroundColor()只會使用我的自定義主題失敗?
更新:我意識到應用程序背景正在我的視圖的背景前呈現! (另外,在我的佈局前面的ProgressBar中,完全遮住了它。)如果將@ color/background_color設置爲完全透明,則會顯示條紋。那麼,問題是,爲什麼我的主題背景在某些視圖/背景前呈現?
主題:
<style name="Basic">
<item name="android:textColor">#000000</item>
<item name="android:background">@color/background_color</item>
</style>
getView():
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout itemView;
Resources res = getResources();
int[] colors = new int[] {res.getColor(R.color.list_stripe_1),res.getColor(R.color.list_stripe_2)};
if (convertView == null){
itemView = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater viewInflater;
viewInflater = (LayoutInflater)getContext().getSystemService(inflater);
viewInflater.inflate(resource, itemView, true);
} else {
itemView = (LinearLayout) convertView;
}
////Omitting code for populating TextViews..
itemView.setBackgroundColor(colors[position%colors.length]);
return itemView;
}