按钮上的图标

问题描述 投票:0回答:2

我有带有 Android 图标的 ImageButton:

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

如何将此图标更改为“确认”。我想使用标准 Android 库中的图标。怎么做?我应该按照什么逻辑在标准 Android 库中找到所需的图标?

android android-imagebutton
2个回答
0
投票

看来您是 Android 新手!

如果您想拥有更多功能,请使用材质按钮

<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"/>

图像按钮只有一个图标,没有任何文字或标签。

您也可以使用 android

<Button
标签,并将其
text
设置为“确认”。

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

尝试将

<Button
标签更改为
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
并查看结果。


0
投票

Android Studio 已经有一堆常用的图标。 获取图标的步骤:

  1. 右键单击
    drawable
    文件夹
  2. 选择新的并选择矢量资源
  3. 点击剪贴画并搜索所需的图标
  4. 选择您的图标并设置名称和颜色
  5. 完成

第1步:

第2步:

第3步:

第4步:

© www.soinside.com 2019 - 2024. All rights reserved.