Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Material Button with Icon on top of Text

Is it possible to have a material button with an icon on top of its text as such:

Buttons

If yes, can you please explain how with some code?

Thank you.

like image 887
Mervin Hemaraju Avatar asked May 25 '20 13:05

Mervin Hemaraju


2 Answers

Now you can use the attribute iconGravity="top".

Something like:

<com.google.android.material.button.MaterialButton
    app:icon="@drawable/...."
    app:iconGravity="top" />

enter image description here

Note: It requires at least the version 1.3.0-alpha02.

like image 129
Gabriele Mariotti Avatar answered Sep 27 '22 17:09

Gabriele Mariotti


You can use the Button attribute "drawableTop" to get the look you are looking for.

android:drawableTop="@drawable/YOUR_DRAWABLE_RESOURCE_NAME"

Below is a sample code on where it is applied:

<Button
     android:id="@+id/your_text_view"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Image"
     android:drawableTop="@drawable/YOUR_DRAWABLE_RESOURCE_NAME"/>
like image 39
Kidus Avatar answered Sep 27 '22 18:09

Kidus