Reputation: 533
I am trying to build the android app and need to build a button with two images and some text .
here is the example image :
how can i build this button in android ? any help would be appreciated .
Upvotes: 1
Views: 4010
Reputation: 1
I face to same problem in my case below code worked ;)
android:layout_width="370dp"
android:layout_height="62dp"
android:layout_marginTop="100dp"
android:drawableLeft="@drawable/flag_us_little"
android:drawableRight="@drawable/ic_arrow"
android:text="English language"
android:textAllCaps="true"
android:textColor="@color/black"/>
Cheers!
Upvotes: 0
Reputation: 3357
Three steps:
in my layout xml file. set the image as the button background:
<Button
android:layout_width="165dp"
android:layout_height="35dp"
android:background="@drawable/background"
android:textColor="#FFFFFF"
android:id="@+id/button"
android:paddingTop="2sp"
android:drawablePadding="-1sp"
></Button>
Final result:
Upvotes: -1
Reputation: 7856
Here is some code to get you started. Lets begin with the background. If that background is not provided to you and you have to create it yourself, lets create a custom_button_bg.xml file and add to your drawable folder.
custom_button_bg.xml Note: that I am just doing the basic shape for you. Adjust shadow and corner radius as you wish
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="@color/teal"
android:startColor="@color/teal"/>
<corners android:radius="4dp"/>
<stroke
android:width="1dp"
android:color="@color/shadow"/>
</shape>
Now simply create your layout, something like below. Just replace the src and labels.
<RelativeLayout
android:layout_width="160dp"
android:layout_height="80dp"
android:gravity="center_vertical"
android:background="@drawable/custom_rounded_white_button">
<ImageView
android:id="@+id/iv_video_cam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/video_cam"/>
<TextView
android:id="@+id/tv_desc"
android:layout_toRightOf="@+id/iv_video_cam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="See a Medical \nDoctor Now"/>
<ImageView
android:layout_toRightOf="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow"/>
</RelativeLayout>
Cheers!
Upvotes: 5
Reputation: 4008
You can use something like this:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:drawableLeft="@drawable/video_camera"
android:drawableRight="@drawable/right_arrow"
android:text="See a Medical\nDoctor Now"/>
Upvotes: 1
Reputation: 3345
Two Options:
You can utilize setBackgroundDrawable()
on your Button
to set the background of the button to an image with the icons you want, then your text will appear above the background.
Or you could try and utilize android:drawableLeft="@drawable/yourimage"
and/or android:drawableRight="@drawable/yourimage"
in your XML file nested in your Button
.
HERE you can find more information on drawableRight/Left
Upvotes: 0