How to add drawable icon along with TextView in Android ?

We wanted to show icons along with titles in our applications, this is possible in one way to add Imageview along with textview and combine both in a LinearLayout while we write layouts.xml.

But all of this has been very simplified by adding just a drawable within textview and mention whether we want the icon to be before or after the textview text.

In this post we just show the related code required to be written in TextView.

$ vim app/src/main/res/layout/profile.xml
<TextView

   android:drawablePadding="5dp"
   android:drawableStart="@drawable/svg_heart_border"
   
/>

Above code adds svg drawable we added before to the textview at the beginning of text line as mentioned by “android:drawableStart”and adds padding of 5 dp between drawable icon and text.

Related :   Determine whether you have an internet connection / Monitor Network Connectivity in Android

You can adjust the icon and text using different parameters as mentioned in https://developer.android.com/reference/android/widget/TextView#attr_android:drawableBottom


lynxbee_ezoic

Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )

   


Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded