如果您使用的是 AppCompat 库,则应该使用 'android:tint' 而不是 'app:tint'。

如果问题仍然存在,请确保您的 ImageView 或其他支持 tint 属性的 View 具有可绘制的背景。如果您在布局中使用的是矢量图标,则可能需要在代码中将其转换为可绘制的背景。您可以使用以下代码:

Drawable drawable = AppCompatResources.getDrawable(context, R.drawable.your_vector_icon);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, your_tint_color);
your_view.setBackground(drawable);
Android Layout 中 app:tint 无效的解决方案

原文地址: https://www.cveoy.top/t/topic/kTOV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录