Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a icon inside a button that shape oval button

I have created a drawable button_oval.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:shape="rectangle">

    <corners android:radius="120dp" />

    <solid android:color="#eceef5" />

    <stroke
        android:width="3dp"
        android:color="#29395e" />

    <size
        android:width="300dp"
        android:height="120dp" />

</shape>

and then i use it on my layout like this:

// I want to add a icon inside this button
    <Button
        android:id="@+id/goToPersonalPage"
        android:layout_width="110dp"
        android:layout_height="50dp"
        android:layout_marginLeft="30dp"
        android:background="@drawable/button_oval"
        android:text="@string/memberButton"
        android:textColor="#29395e"
        android:textSize="18dp" />

I want to add an icon inside the Button, is it any possible to complete it by changing my button_oval.xml?

The final output should look Just like the image below :

enter image description here

Any help would be greatly appreciated.

like image 400
Morton Avatar asked Dec 07 '25 08:12

Morton


1 Answers

You have to add these lines in your Button element-

android:drawableLeft="@mipmap/ic_launcher_round" // to set an icon
android:drawablePadding="10dp" // to set the padding of icon from text
android:paddingLeft="20dp"  // to set the padding of the icon and text

adjust the values according to your need.

It will look like-

enter image description here

like image 90
D_Alpha Avatar answered Dec 08 '25 20:12

D_Alpha