Android:我想改变我的 ImageView 的颜色

标签 android imageview

我想改变我的 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/

相关文章:

android - 如何禁用或删除屏幕键盘上的设置按钮

android - 如何将渐变定义为圆形progressBar

安卓工作室 : Can't add Views on GridLayout. android/view/View$OnUnhandledKeyEventListener

javascript - 在点击上传 javascript/jquery 之前显示图像

Android 避免 ImageView 中的图像缩放以像 Html 那样进行图像映射

android - 如何在java中获取图像名称?

java - onTaskRemoved() 在 Oppo 设备中未被调用

android - 如何同时在多个设备上运行 android Instrument 测试

android - 从具有内部存储的Android手机上的图库中获取图像

android - RecyclerView.Adapter 和 ImageView.getWidth()