首页 > 解决方案 > 如何更改按钮中的图标颜色?

问题描述

我创建了带有文本和图标的按钮:

<Button
        android:id="@+id/btnLinkToProfile"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:text="@string/profile"
        android:gravity="left|center_vertical"
        android:textAllCaps="false"
        android:textColor="@color/text"
        android:textSize="15dp"
        android:drawableLeft="@drawable/profile"/>

我想设置图标颜色,如何在标签中执行此操作,<Button/>或者只能在<ImageView/>标签中设置?

标签: androidbuttoncolorsicons

解决方案


您可以使用 android:drawableTint="#000000" 作为可绘制对象

<Button
    android:id="@+id/btnLinkToProfile"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:text="@string/profile"
    android:gravity="left|center_vertical"
    android:textAllCaps="false"
    android:textColor="@color/text"
    android:textSize="15dp" 
    android:drawableLeft="@drawable/profile"
    android:drawableTint="#000000"
    android:drawableTintMode="src_in"/>

谢谢


推荐阅读