我正在Android中开发一周的数据应用程序。我想设置工作日的背景颜色(例如:星期五)。我正在使用 xml 中的列表视图。 非常感谢您的建议,
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:
}
等等,在案例里面放你改变的逻辑.