如何在andoidx的AppCompatImageButton中设置图像颜色?因为我在AppCompatImageButton中尝试在xml中设置颜色背景色,但是没有设置。对此有什么解决方案吗?
发布于 2020-03-12 18:33:14
你应该通过染色来改变图像的颜色,
<androidx.appcompat.widget.AppCompatImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="@color/colorPrimary"
app:srcCompat="@drawable/ic_home_black_24dp"/>发布于 2020-03-12 18:23:43
试试这个:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.appcompat.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Backgroundtint"/>
</androidx.constraintlayout.widget.ConstraintLayout>这将是输出:

我想您指的是Button而不是Imagebutton,因为您不能在XML中更改图像的颜色。
https://stackoverflow.com/questions/60651883
复制相似问题