Android: circular feedback on ImageButton

How can I set a background like a circular image so that when I click on it, the background shows a round background, not a square background?

The first round (in the action bar):

Round

Square (regular ImageButton):

Square

+4
source share
1 answer

I get it!

enter image description here

Im using a selector called button_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/circle_background" />
</selector>

And a round background drawing: circle_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#1f000000" />
</shape>

Now just set it as the background for ImageView:

<ImageButton
    android:background="@drawable/button_background"
    android:id="@+id/edit"
    android:layout_width="wrap_content"
    android:layout_height="72dp"
    android:layout_alignParentRight="true"
    android:contentDescription="@string/popup_edit"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:src="?attr/more" />

Et voilá :)

+4
source

All Articles