0

May i ask how to put icon on my button like the image below?

And also where can i have resources or sample resources of buttons like this?

enter image description here

2

5 Answers 5

1

You'll need to set the drawable to the left of your Button. Either via xml or programmatically.

Sign up to request clarification or add additional context in comments.

3 Comments

do you have a sample of it?
samples are all over the net, sir.
Since there is no code from your side to add to, I'll stick with @Nfear's answer.
0

Either create a button and set a compound drawable or create an ImageButton.

Comments

0
<TextView android:id="@+id/login_with_facebook"
          android:layout_width="100dp"
          android:height="48dp"
          android:text="FACEBOOK"
          android:gravity="center"
          android:drawableLeft="@drawable/facebook_icon_48_x_48"
          android:clickable="true"/>

2 Comments

textview? what i was asking was button sir. Thanks.
sir, its clickable as you can see, and user won't see any difference if this button or textview
0
<Button android:drawableLeft="@drawable/image"
         android:text="facebook"/>

If u want space between image and text, then give drawablePadding Like:

<Button android:drawableLeft="@drawable/image"
         android:text="facebook"
         android:drawablePadding="10dp"/>

Comments

0

using RelativeLayout it can be done easily. here I got snippet for you,

    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">

        <Button 
            android:id="@+id/fb_logo_button"
            android:text=""
            android:background="fb_logo"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>

        <Button 
            android:layout_toRightOf="@id/fb_logo_button"
            android:id="@+id/fb_text_button"
            android:text="Facebook"
            android:textAlignment="center"
            android:background="@android:color/holo_blue_bright"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>

    </RelativeLayout>

this will ensure that whatever your images are for respective DPIs, it will align this layout to center horizontally. Within this layout logo will be always to left of text as in picture.

This is applicable when your parent is also a RelativeLayout. If you got LinearLayout as parent then in above RelativeLayout tag change android:layout_centerHorizontal="true" to android:layout_gravity="center_horizontal"

I can't test it in eclipse as I'm out of home. Try this and let me know. Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.