1

The default style of a ImageButton is square.

<ImageButton
    android:id="@+id/imgNextPlayer"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@android:color/white"
    android:layout_gravity="top"
    android:tint="#757575" />
Sven-Michael Stübe
  • 14,560
  • 4
  • 52
  • 103
J. Joe
  • 383
  • 6
  • 26

2 Answers2

2

Have you tried creating a shape in the drawable folder mybuttonshape.xml:

like this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <solid android:color="#FFFFFF"/> 
    <corners android:radius="10dp"/>
</shape>

then setting the background of your button to this drawable:

<ImageButton
    android:id="@+id/imgNextPlayer"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@drawable/mybuttonshape"
    android:layout_gravity="top"
    android:bottomRightRadius="10dp"
    android:bottomLeftRadius="10dp"
    android:topLeftRadius="10dp"
    android:topRightRadius="10dp" />

check this question for other options

Community
  • 1
  • 1
Iain Smith
  • 9,230
  • 4
  • 50
  • 61
2

You would set your android:background="@android:.... to be a drawable:

android:background="@drawable/myellipsebutton"

Then add a drawable called myellipsebutton.xml:

  • Resource/Drawable/myellipsebutton.xml

In this drawable resource, you can define the shape of the button, in this case I'm using oval instead of rectangle, line and ring are also available:


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="oval">
            <gradient android:startColor="#F44336" android:endColor="#E57373" android:angle="270" />
            <stroke android:width="10dp" android:color="#607D8B" />
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="oval">
            <gradient android:startColor="#3F51B5" android:endColor="#9FA8DA" android:angle="270" />
            <stroke android:width="10dp" android:color="#607D8B" />
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <gradient android:startColor="#2196F3" android:endColor="#BBDEFB" android:angle="270" />
            <stroke android:width="1dp" android:color="#607D8B" />
        </shape>
    </item>
</selector>

enter image description here

SushiHangover
  • 73,120
  • 10
  • 106
  • 165