<imageView
android: Layout_width="match_parent"
android: Layout_width="match_parent"
android:src="@drawable/star_icon"
android:I'd="[email protected]"/>
我需要改变图标的颜色色调编程帮我如何以编程方式更改imageView的色调颜色?
<imageView
android: Layout_width="match_parent"
android: Layout_width="match_parent"
android:src="@drawable/star_icon"
android:I'd="[email protected]"/>
我需要改变图标的颜色色调编程帮我如何以编程方式更改imageView的色调颜色?
试试这个,
imageViewDone.setColorFilter(ContextCompat.getColor(context, R.color.yourcolor), android.graphics.PorterDuff.Mode.MULTIPLY);
使用
imageView.setColorFilter(int color, PorterDuff.Mode mode)
或
imageView.setColorFilter(int color)
参考:https://developer.android.com/reference/android/widget/ImageView.html#setColorFilter(int)
您可以使用颜色过滤
imageView.setColorFilter(ContextCompat.getColor(mContext, R.color.CHOICE_COLOUR), android.graphics.PorterDuff.Mode.MULTIPLY);
如果您想使用默认达夫模式的imagevview你可以喜欢
imageView.setColorFilter(int color)
,但如果你想改变颜色达夫般的光芒到多个或黑暗然后你应该使用:
imageView.setColorFilter(int color, PorterDuff.Mode mode)
您可以在代码中通过改变色彩,很容易:
imageView.setColorFilter(Color.argb(255, 255, 255, 255));
如果你想那么色调:
imageView.setColorFilter(ContextCompat.getColor(context,
R.color.COLOR_YOUR_COLOR));
与模式:
imageView.setColorFilter(ContextCompat.getColor(context,
R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.MULTIPLY);
在我案例:
imgBottomDivider.setColorFilter(ContextCompat.getColor(getContext(),
mPreferences.isNightMode() ? R.color.colorWhite : R.color.colorBlack));
检查这个https://stackoverflow.com/questions/20121938/how-to-set-tint-for-an-image-view-programmatically-in-android – amarok
谢谢老兄它的工作.. – sukesh