0

I'm adding MaterialButton to my android project and it only shows the text instead of both text and icons, here is my code :

    <com.google.android.material.button.MaterialButton
        android:id="@+id/homeBtn1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="8dp"
        android:gravity="center"
        android:textAllCaps="true"
        android:textColor="#F8F8F8"
        android:background="#3F51B5"
        android:text="@string/findTrans"
        app:icon="@drawable/white_bus_icon"
        app:iconGravity="textStart"
        app:iconTint="@null"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView2"
         />

and here is how the buttons looks :

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116

2 Answers2

4

Based on This answer I've found out that I just needed to add these lines to my app style file

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">

And of course after having the dependencies added to your Gradle file :

    implementation 'com.google.android.material:material:1.0.0'
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116
1

Remove the line app:iconTint="@null" and try again