【问题标题】:How can I change icons color in button?如何更改按钮中的图标颜色?
【发布时间】:2019-01-23 13:26:29
【问题描述】:

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

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

我想设置图标颜色,如何在&lt;Button/&gt;标签中设置或者只能在&lt;ImageView/&gt;标签中设置?

【问题讨论】:

标签: android button colors icons


【解决方案1】:

您可以将 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"/>

谢谢

【讨论】:

    【解决方案2】:

    您可以使用 ImageButton 并设置颜色

    android:tint="@color/myColour"
    

    【讨论】:

    • 那么带有 ImageButton 的文本呢?
    • 当我尝试将 chromecast mini 控制器按钮自定义为白色时,此解决方案对我有用。我有一个白色图标,但它一直显示为黑色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-21
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多