android - 如何更改按钮中的图标颜色?
问题描述
我创建了带有文本和图标的按钮:
<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/>
标签中设置?
解决方案
您可以使用 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"/>
谢谢
推荐阅读
- php - 将结果对话 ID 分组为一个标签
- java - spring @Query 注解中的 HQL 查询
- angular - 与根据条件更改 matform 字段相关的问题
- javascript - Vuetify - 在开关内显示文本
- python - pytorch 初学者:torch.data.new() torch.new()
- modelica - 当结果中只有 2 个元素时,对 Dymola 的输出结果进行后处理
- docker - 即使我在 docker run 时添加了 node_modules 作为卷,也无法在 docker 上找到模块
- javascript - 尝试传递参数时未定义未捕获的引用错误 xyz
- c# - 如何使用带有 tiffsep1 设备的带有 ghostscript/postscript 的渐变在 pdf 中写一行?
- r - httr::content 返回对象类型 externalptr