user6299584
user6299584

Reputation:

Button with icon and text

I would like to make a Button like that in Android :

Connexion button

But I don't know how to do that. Do I have to use a RelativeLayout with some elements (ImageView, TextView, separator,...) ?

I really don't know the best practice.

Upvotes: 7

Views: 8277

Answers (5)

Sathish Kumar J
Sathish Kumar J

Reputation: 4335

With text and an icon, using the Button class with the android:drawableLeft attribute:

Try this:

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text Here"
android:drawableLeft="@drawable/your_image"
 />

Upvotes: 2

Marcin Orlowski
Marcin Orlowski

Reputation: 75609

You can use just <Button> and set icon you want using i.e. android:drawableLeft attribute.

See docs: https://developer.android.com/guide/topics/ui/controls/button.html

Upvotes: 1

Jay Rathod
Jay Rathod

Reputation: 11245

You can use Button with Property android:drawableLeft="@drawable/ic_done".

Refer this.

 <Button
        android:id="@+id/button111111"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawablePadding="5dp"
        android:layout_centerHorizontal="true"
        android:drawableLeft="@drawable/ic_done"
        android:text="Facebook" />

EDIT 1:

If you want to do it without using Button with Property android:drawableLeft="@drawable/ic_done" Then.

Refer this.

Create XML file named it Shape.xml inside res -> drawable folder.

If you don't see drawable folder in res directory then create folder named drawable.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="3dip"
        android:color="@android:color/black" />
    <corners android:radius="10dip" />
    <padding
        android:bottom="10dip"
        android:left="10dip"
        android:right="10dip"
        android:top="10dip" />
</shape>

Then refer this Layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/shape"
    android:gravity="center_vertical">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/app_name"
        android:src="@mipmap/ic_launcher" />

    <View
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:background="@android:color/darker_gray" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight="1"
        android:background="@null"
        android:text="Submit" />


</LinearLayout>

Here is screen.

enter image description here

Note : Change your Drawable and Color as of your choice.

Upvotes: 7

harsha javagal
harsha javagal

Reputation: 81

I did for you. Save the image and set as background for the button

i

Upvotes: 3

harsha javagal
harsha javagal

Reputation: 81

Edit the image to remove the extra area around border and set the image as background

Upvotes: 0

Related Questions