Center a drawable in a Button with background and no text

Is there a way to center the drawable without abandoning Button

So you can have both (background & drawable) by using ImageView as below: (So No need to use Button)

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/an_icon"
    android:background="@drawable/a_background" />

For OnClick of ImageView:

findViewById(R.id.imageView1).setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }
});

The easiest solution is to use ImageButton widget:

<ImageButton
    (...)
    android:background="@drawable/a_background"
    android:src="@drawable/an_icon"
    />

Tags:

Android

Button