我想改变我的 imageView 的颜色。 粘贴以下代码:-
首先我粘贴了 footer.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#f1eeee"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/fHome"
android:background="@drawable/colorchanged"
android:src="@drawable/home" /> <!-- your image here -->
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/fAttendence"
android:src="@drawable/att" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/fTarget"
android:src="@drawable/target" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/fReport"
android:src="@drawable/report" />
</LinearLayout>
pasted .png which i used in this file
pasted .png which i used in this file
当我点击 imageView 时,我想在其上设置蓝色。
有人可以帮我吗?
最佳答案
您可以使用如下所示的 ColorFilter
在 View 点击时触发:
yourImageView.setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.MULTIPLY);
请注意,这实际上会更改 yourImageView
实例的状态,因此您需要一个变量来跟踪它。
关于Android:我想改变我的 ImageView 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39406508/