Java 为什么setBackgroundColor()仅在我的自定义主题中失败?
我想我成功地创建了一个条带化的Android ListView,其中列表项的背景颜色是交替的。当我使用Theme.Holo.Light作为我的应用程序的主题时(在清单中),它可以完美地工作 然而,当我为我的应用程序定义了一个自定义主题,使用自定义背景色时,条纹消失了,取而代之的是在我的主题中定义的单一背景色为什么我的自定义主题的背景色不能被getView()中的setBackgroundColor()覆盖?如何解决此问题?谢谢 更新:我意识到应用程序背景是在我的视图背景前面呈现的!(另外,在我的布局中的进度条前面,完全遮挡它。)如果我将@color/background\u color设置为完全透明,则条带将显示出来。因此,问题是,为什么我的主题的背景呈现在一些视图/背景前面? 主题:Java 为什么setBackgroundColor()仅在我的自定义主题中失败?,java,android,styles,themes,Java,Android,Styles,Themes,我想我成功地创建了一个条带化的Android ListView,其中列表项的背景颜色是交替的。当我使用Theme.Holo.Light作为我的应用程序的主题时(在清单中),它可以完美地工作 然而,当我为我的应用程序定义了一个自定义主题,使用自定义背景色时,条纹消失了,取而代之的是在我的主题中定义的单一背景色为什么我的自定义主题的背景色不能被getView()中的setBackgroundColor()覆盖?如何解决此问题?谢谢 更新:我意识到应用程序背景是在我的视图背景前面呈现的!(另外,在我的
<style name="Basic">
<item name="android:textColor">#000000</item>
<item name="android:background">@color/background_color</item>
</style>
不要在主题中使用设置android:background,而是设置android:windowBackground。我还没有完全研究为什么不能用setBackgroundColor()覆盖主题集背景,或者为什么使用android:background会导致微调器模糊,但是使用windowBackground解决了这个问题
@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;
}