Adriano Bellavita
Adriano Bellavita

Reputation: 141

Customize button in android

I wanto to customize a generic button in android, by extendong Button class.

I Simply want that default android button will be displayed with an horizontal line in the middle of the button.

So this is the draw method implementation:

protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Paint paint = new Paint();
    paint.setColor(Color.RED);
    canvas.drawLine(0, getHeight()/2, getWidth(), getHeight()/2, paint);
}

and this is the button inserted in a layout

<Button
    class="com.example.backproject.ShadowButton"
android:background="@android:color/transparent" 
    android:id="@+id/myButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

</Button>

But the button does not change.

Why?

TY in advance!

Upvotes: 0

Views: 633

Answers (2)

Chirag
Chirag

Reputation: 56925

Use this <com.example.backproject.ShadowButton instead of <Button in your xml file and remove class="com.example.backproject.ShadowButton" .

Edit : Code

<com.example.backproject.ShadowButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@android:color/transparent" 
    android:id="@+id/myButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

Upvotes: 2

MAC
MAC

Reputation: 15847

You have created customized button then use that like this

<com.example.backproject.ShadowButton
    android:background="@android:color/transparent" 
    android:id="@+id/myButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

Upvotes: 2

Related Questions