Search This Blog

28 May 2010

Customizing the Views

Let's start by creating a basic class:
F:\work> mvn archetype:generate -DarchetypeCatalog=
Choose the galatea-archetype plugin
artifactId: CustomViewTest
version: 1.0-SNAPSHOT

Assuming your emulator is running...
F:\work> cd CustomViewTest
F:\work\CustomViewTest> mvn clean install

Create a new class.  In my case I created src\main\java\org\eoti\android\

public class CustomTextView
extends TextView
    public CustomTextView(Context context) {

    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    protected void onDraw(Canvas canvas) {
        Paint cornsilk = new Paint(Paint.ANTI_ALIAS_FLAG);

        canvas.drawLine(0, 0, this.getMeasuredWidth(), this.getMeasuredHeight(), cornsilk);
        canvas.drawLine(this.getMeasuredWidth(), 0, 0, this.getMeasuredHeight(), cornsilk);

Update src\main\android\res\layout\main.xml
Replace this line:
with this line:

Redeploy (mvn clean install) and run the app. You should see lines behind the text.

No comments:

Post a Comment