我在android中制作了一个自定义日历,为此我使用了自定义网格视图,现在我想更改日历中所选日期的颜色,但是我不知道该怎么做,我的代码如下,我正在附上自定义网格项和Java代码。请提供帮助。谢谢。
Grid_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/calendar_cell"
android:gravity="center"
android:orientation="vertical"
android:padding="2dip" >
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#545454"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="@+id/date_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dot"
android:visibility="gone" />
</LinearLayout>
代码
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
((CalendarAdapter) parent.getAdapter()).setSelected(v);
selectedGridDate = CalendarAdapter.dayString.get(position);
String[] separatedTime = selectedGridDate.split("-");
String gridvalueString = separatedTime[2].replaceFirst("^0*",
"");// taking last part of date. ie; 2 from 2012-12-02.
int gridvalue = Integer.parseInt(gridvalueString);
// navigate to next or previous month on clicking offdays.
if ((gridvalue > 10) && (position < 8)) {
setPreviousMonth();
refreshCalendar();
} else if ((gridvalue < 7) && (position > 28)) {
setNextMonth();
refreshCalendar();
}
((CalendarAdapter) parent.getAdapter()).setSelected(v);
showToast(selectedGridDate);
}
});
private TextView txtDate;
....
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
//add your code here
if(txtDate!=null)
{
txtDate.setTextColor(Color.parseColor("#000000")); // the color you want for unselected date
}
txtDate = (TextView) v.findViewById(R.id.date);
txtDate.setTextColor(Color.parseColor("#E5AC56")); // the color you want for selected date
.....
.....
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句