Icons on button

42 views Asked by At

I have ImageButton with Android icon:

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="Icon"
                android:src="@drawable/ic_android"
                />

How to change this icon to "confirm". I would like to use icon from standard Android library. How to do that? What logic I should go find required icon in standard Android library?

2

There are 2 answers

0
Pawan Harariya On BEST ANSWER

Android Studio already has bunch of commonly used icons. Steps to get the icon :

  1. Right-click on drawable folder
  2. Select new and the select vector asset
  3. Click on clipart and search for the required icon
  4. Choose your icon and set name and color
  5. Finish

Step 1 : Step 1

Step 2 : Step 2

Step 3 : Step 3

Step 4 : enter image description here

2
C.F.G On

It seems that you are new to Android!

use Material button if you like to have more features.

<com.google.android.material.button.MaterialButton
            android:id="@+id/confirmBtn"
            style="@style/Widget.Material3.Button.IconButton.Filled"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:text="Confirm"
            android:textAlignment="center"
            android:textSize="16dp"
            app:icon="@drawable/ic_android
            app:iconGravity="textEnd"
            app:iconPadding="8dp"
            app:backgroundTint="@color/green"/>

Image button has only a icon without any text or label.

You can also use android <Button tag instead and set its text to "confirm".

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableEnd="@drawable/ic_android"
        android:text="Confirm"/>

Try to change <Button tag to <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton and see the result.