Android Studio - add an icon to the button (vector asset)

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

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"/ >

Související obsah

android

programovani

android-studio

Komentáře

Vaše reakce na Android Studio - přidání ikonky do tlačítka (vector asset, button)

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.