Android应用中的工作日的setbackground颜色

时间:2016-01-30 23:12:16

标签: android listview background-color weekday

我正在Android中开发一周数据应用程序。我想在工作日设置背景颜色(例如:星期五)。我在xml中使用 listview 。非常感谢你的建议,

 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);
}

1 个答案:

答案 0 :(得分:0)

为了获得这一天,请执行以下操作:

Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK); 

根据当天设置背景:

switch (day) {
case Calendar.SUNDAY:


case Calendar.MONDAY:

}

依此类推,在案件内部提出了改变你的逻辑。