In this tutorial, you will learn to add icon and text in a button. Adding icon in android button is very easy. You can add icons in android button using XML attributes android:drawableLeft, android:drawableRight, android:drawableTop and android:drawableBottom.
If you want to display image in the left side of button text use drawableLeft property, if you want to display image in right side of button text use drawableRight properties, similarly if you want to display icon/image in top of text i.e. text below icon uses drawableTop and to display icon in below text uses drawableButtom property.
Here, you will learn to display image in four sides of android button left, right, top and button using relative layout / linear layout.
Related:
Android ImageButton Example
Android EditText Example
How to Set Android Button and TextView Border Color
Following is the XML layout file where I have added different buttons to display image/icon in different side of button with text.
res/layout/android_button_with_icon_text.xml
Following is the default java code of activity file.
src/ AndroidButtonWithIconAndText.java
Following is the content of strings.xml file
res/values/strings.xml
Now, run your Android Button with Icon and Text application, you will see the five buttons with icon and text.
If you want to display image in the left side of button text use drawableLeft property, if you want to display image in right side of button text use drawableRight properties, similarly if you want to display icon/image in top of text i.e. text below icon uses drawableTop and to display icon in below text uses drawableButtom property.
Here, you will learn to display image in four sides of android button left, right, top and button using relative layout / linear layout.
Related:
Android ImageButton Example
Android EditText Example
How to Set Android Button and TextView Border Color
Android Example: How to Use Icon and Text Together in Android Button
Following is the XML layout file where I have added different buttons to display image/icon in different side of button with text.
res/layout/android_button_with_icon_text.xml
Following is the default java code of activity file.
src/ AndroidButtonWithIconAndText.java
Following is the content of strings.xml file
res/values/strings.xml
Now, run your Android Button with Icon and Text application, you will see the five buttons with icon and text.
Comments
Post a Comment