如何在 Android Imageview
中将 xml
中的一种颜色替换为另一种颜色(黑到白)?
我在水平线性布局
中放置了3个图像,每个图像都有透明背景,但主要是黑色。我想从 Android xml 中将每个图像的颜色替换为白色。
我不知道如何做到这一点,您建议如何实现这一目标?
到目前为止我的代码如下:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp">
<ImageView
android:id="@+id/imageview_se"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitXY"
android:src="@drawable/search"
android:backgroundTint=""/>
<ImageView
android:id="@+id/imageview_hea"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitXY"
android:src="@drawable/heart"/>
<ImageView
android:id="@+id/imageview_menu"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitXY"
android:src="@drawable/menu" />
</LinearLayout>
我的图标:
最佳答案
您正在谈论将 ImageView 的源 (android:src) 更改为白色,对吧?不是背景色?如果是这样,您无法在 xml 中执行此操作,您必须以编程方式更改颜色。
ImageView seImageView = (ImageView) findViewById(R.id.imageview_se);
ImageView heaImageView = (ImageView) findViewById(R.id.imageview_hea);
ImageView menuImageView = (ImageView) findViewById(R.id.imageview_menu);
seImageView.setColorFilter(Color.parseColor("#ffffff"));
heaImageView.setColorFilter(Color.parseColor("#ffffff"));
menuImageView.setColorFilter(Color.parseColor("#ffffff"));
关于java - 如何在 Android Imageview 中将 xml 中的一种颜色替换为另一种颜色(从黑到白)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27982339/