Android Studio - add an icon to the button (vector asset)
Hi
how do I add an icon to a button in Android Studio like it's done for the web using FontAwesome? Apparently this is hidden somewhere in Android Studio and I can't find it.
I just want to place an icon in the left part of the button and text behind it.
Thanks
Hi,
There are a lot of vector icons in Android Studio (simply something like Font Awesome), they can be used as follows:
1.) Right click Res> New> Vector Asset
2.) Click on Clip Art and select the desired icon (image, Vector Asset)
3.) When we choose eg ic_baseline_done_24, we give Next and Finish
4.) This created the file res/drawable/ic_baseline_done_24.xml
We then define the button as follows:
If we just want an icon in the middle without text:
how do I add an icon to a button in Android Studio like it's done for the web using FontAwesome? Apparently this is hidden somewhere in Android Studio and I can't find it.
I just want to place an icon in the left part of the button and text behind it.
Thanks
REPLY
Hi,
There are a lot of vector icons in Android Studio (simply something like Font Awesome), they can be used as follows:
1.) Right click Res> New> Vector Asset
2.) Click on Clip Art and select the desired icon (image, Vector Asset)
3.) When we choose eg ic_baseline_done_24, we give Next and Finish
4.) This created the file res/drawable/ic_baseline_done_24.xml
We then define the button as follows:
< Button
android:id="@+id/btn_5"
android:layout_width="100dp"
android:layout_height="35dp"
android:textSize="12sp"
android:drawableLeft="@drawable/ic_baseline_done_24"
android:text="Text" / >
If we just want an icon in the middle without text:
< Button
android:id="@+id/btn_5"
android:layout_width="36dp"
android:layout_height="35dp"
android:textSize="12sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:drawableLeft="@drawable/ic_baseline_done_24"/ >