--- HighlightedDatePicker.java---
import java.util.Map;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.DatePicker;
public class HighlightedDatePicker extends DatePicker {
Rect mRect = new Rect();
public HighlightedDatePicker(Context arg0, AttributeSet arg1, Map arg2) {
super(arg0, arg1, arg2);
/* Color is set by AA (alpha) then RRGGBB
* I need to set the background to be transparent in order to paint
* on the canvas background. The background can also bet set to be a color,
* and fully opaque
*/
this.setBackgroundColor(0x00FFFFFF);
/* Create a new Rectangle object each time the calendar is created
* for testing purposes.
*/
mRect = new Rect((int)((float)Math.random() * 100),100,40,40);
}
@Override protected void onDraw(Canvas canvas) {
// Do the standard draw
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
canvas.drawRect(mRect, paint);
}
}
----- ShowData.java----
import android.app.Activity;
import android.os.Bundle;
public class ShowData extends Activity {
private HighlightedDatePicker dp;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.show_data);
dp = (HighlightedDatePicker) this.findViewById(R.id.super_date);
dp.init(2008, 3, 20, 1, null);
}
}
--res/layout/show_data.xml---
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget166"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.foo.android.bar.HighlightedDatePicker
android:id="@+id/super_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="7px"
android:layout_y="8px" />