Android应用程序中一周一天的背景色
我正在用Android开发一周的数据应用程序。我想为工作日(例如:星期五)设置背景色。我正在使用xml中的列表视图。非常感谢你的建议Android应用程序中一周一天的背景色,android,listview,background-color,weekday,Android,Listview,Background Color,Weekday,我正在用Android开发一周的数据应用程序。我想为工作日(例如:星期五)设置背景色。我正在使用xml中的列表视图。非常感谢你的建议 private void addDateView(LinearLayout layout, String text, boolean isCurrentDay) { listview child = new listview(layout.getContext()); if (isCurrentDay) {
private void addDateView(LinearLayout layout, String text,
boolean isCurrentDay) {
listview child = new listview(layout.getContext());
if (isCurrentDay) {
child.setBackgroundColor(Color.rgb(242, 199, 125));
} else {
child.setBackgroundColor(Color.WHITE);
}
child.setGravity(Gravity.CENTER);
child.setTextColor(Color.RED);
[enter image description here][1]child.setPadding(8, 8, 8, 8);
layout.addView(child, (SCREEN_WIDTH / 7), 50);
}
要获得这一天,请执行以下操作:
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
要根据日期设置背景,请执行以下操作:
switch (day) {
case Calendar.SUNDAY:
case Calendar.MONDAY:
}
以此类推,将您不断变化的逻辑放入机箱中。此代码有什么问题?看起来不错,谢谢你的回复,我在boolean和int方面有错误。我不知道如何解决。如果你有任何代码或链接,这将是伟大的。谢谢!将完整的错误消息添加到问题中,并指出错误日志中出现的代码行