vico
vico

Reputation: 18251

Icons on button

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?

Upvotes: 0

Views: 321

Answers (2)

Pawan Harariya
Pawan Harariya

Reputation: 1404

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

Upvotes: 0

C.F.G
C.F.G

Reputation: 1463

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.

Upvotes: 0

Related Questions