Android Material Button with Icon on top of Text

前端 未结 2 1498
轮回少年
轮回少年 2021-01-23 02:55

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

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

Thank you.

相关标签:
2条回答
  • 2021-01-23 03:43

    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"/>
    
    0 讨论(0)
  • 2021-01-23 03:56

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

    Something like:

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

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

    0 讨论(0)
提交回复
热议问题