Android Button Material Design With Image

I now use MaterialDesignLibrary

I want to use with the image

<com.gc.materialdesign.views.ButtonFlat
                android:id="@+id/buttonflat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#1E88E5"
                android:text="Button" />

How can I do that?

Upvotes: 1

Views: 8311

Answers (3)

Zeeshan Ali
Zeeshan Ali

Reputation: 2261

 <com.google.android.material.button.MaterialButton
        android:id="@+id/btn_restore"
        android:layout_width="match_parent"
        android:layout_height="54dp"
        android:background="@color/default_btn_color"
        android:gravity="center"
        android:text="@string/restore"
        android:textColor="@color/dark_grey"
        android:textStyle="bold"
        app:backgroundTint="@color/default_btn_color"
        app:icon="@drawable/ic_restore_download"
        app:iconGravity="textStart"
        app:iconTint="@color/dark_grey"
        tools:text="@string/restore" />

Upvotes: 5

Attaullah
Attaullah

Reputation: 4021

<com.gc.materialdesign.views.ButtonFloat
                    android:id="@+id/buttonFloat"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentBottom="true"
                    android:layout_marginRight="24dp"
                    android:background="#1E88E5"
                    materialdesign:animate="true"
                    materialdesign:iconDrawable="@drawable/pencil" />

last line use to get an image from drawable folder.. or you can easily background attribute first make selector then

android:background="@drawable/mbtnselector"

and add xml name space

 xmlns:materialdesign="http://schemas.android.com/apk/res-auto"

If you set the Drawable Icon by code in java it's like that:

buttonFloat = (com.gc.materialdesign.views.ButtonFloat)findViewById(R.id.buttonFloat);
if (buttonFloat != null) {
    buttonFloat.setDrawableIcon(getResources().getDrawable(R.drawable.ic_action_new));
}

Upvotes: -1

Diego Balestra
Diego Balestra

Reputation: 9

<com.gc.materialdesign.views.ButtonFlat
            android:id="@+id/buttonflat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#1E88E5"
            android:background-image="src=<src>"
            android:text="Button" />

Upvotes: -1

Related Questions