1

Using Material design, I need to create a button with text and Image aligned vertically.

  <com.google.android.material.button.MaterialButton
                                android:id="@+id/btn"
                                style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
                                android:layout_width="160dp"
                                android:layout_height="160dp"
                                android:clickable="true"
                                android:elevation="4dp"
                                android:fontFamily="@font/roboto_bold"
                                android:onClick="myfunction()"
                                android:text="BUTTON"
                                android:textColor="@android:color/black"
                                android:textSize="20dp" />
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Himavan
  • 385
  • 3
  • 16
  • You can't do it currently. Check this feature request on [github repo](https://github.com/material-components/material-components-android/issues/671#issuecomment-545347915). – Gabriele Mariotti Oct 23 '19 at 11:40

1 Answers1

4

Use android:drawableBottom="..." or android:drawableTop="..." to align text and an image vertically.

Button with drawableTop

dependencies {
  implementation "com.google.android.material:material:1.2.0-alpha01"
}
  <com.google.android.material.button.MaterialButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:drawableTop="@drawable/ic_android_black_24dp"
    android:drawableTint="@color/white"
    app:backgroundTint="#429835"
    android:layout_marginStart="32dp"
    android:layout_marginEnd="32dp"
    android:text="Hello world" />
Sandi
  • 2,415
  • 1
  • 13
  • 11
  • It is wrong. It is a `MaterialButton`. It uses `app:icon` and `app:iconGravity` attrs. – Gabriele Mariotti Oct 23 '19 at 11:39
  • No it's not since it's also a `TextView`, try it out yourself on a new project with the latest version of the Material library. I will update my post with a screenshot. – Sandi Oct 23 '19 at 11:45