在AppCompatImageButton中设置图片颜色或在Android中设置ImageView的图片颜色,可以通过以下步骤实现:
implementation 'androidx.appcompat:appcompat:1.3.1'
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_image" />
或
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_image" />
AppCompatImageButton imageButton = findViewById(R.id.imageButton);
imageButton.setColorFilter(ContextCompat.getColor(this, R.color.your_color), PorterDuff.Mode.SRC_IN);
或
ImageView imageView = findViewById(R.id.imageView);
imageView.setColorFilter(ContextCompat.getColor(this, R.color.your_color), PorterDuff.Mode.SRC_IN);
其中,R.color.your_color是你想要设置的颜色资源。
这样,你就可以在AppCompatImageButton或ImageView中设置图片的颜色了。
推荐的腾讯云相关产品:腾讯云移动推送(https://cloud.tencent.com/product/umeng_push)可以帮助开发者实现消息推送功能,适用于App开发中的消息通知场景。
领取专属 10元无门槛券
手把手带您无忧上云