Search code examples
androidmaterial-designandroid-buttonmaterial-components-android

Why the icon on the button looks so big?


I'm trying to give an icon to the button but it looks like this!

enter image description here

XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button.Icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test Button"
        app:icon="@drawable/ic_facebook"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

I'm tried to find a related issue on the internet but unfortunately can't find anything related to this issue or I did not search enough


Solution

  • Try adding app:iconSize="24dp" property to your button in your xml. You can change 24dp whatever size you want. One thing to mention, this will work only with MAterialButton.