-1

I want to create buttons in my android application, just like shown in the image below

enter image description here

you can se all the four buttons below.

I want to give them a custom color background and then an icon on the top. There is no way I'm able to adjust the icon at the centre of button.

How can I achieve the desired effect?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Yatendra Rathore
  • 333
  • 2
  • 13

2 Answers2

3

You can do this with FrameLayout and for circle background you need to create a shape drawable file. Refer my answer here.

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/round_shape"
        android:clickable="true"
        android:focusable="true"
        android:visibility="visible"
        android:foreground="?android:attr/selectableItemBackground"
        android:padding="4dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_star_border_black_24dp"/>
    </FrameLayout>

round_shape.xml add this file in drawable folder

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <gradient
        android:angle="270"
        android:startColor="@color/profile_grey"
        android:endColor="@color/profile_grey"/>

</shape>
Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74
0

Create Drawable and use that drawable as Button Background.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="oval">
        <stroke android:color="#e1e1e1"
            android:width="0.5dp"/>
        <solid android:color="@android:color/white"/>
    </shape>
  </item>
</selector>

This Code create a circle with white background.