Android Drawable 在代码中实现android:tint效果
16lz
2021-01-23
第一种不去区分版本,使用V4包的android.support.v4.graphics.drawable.DrawableCompat
ImageView image = new ImageView(context);Drawable up = ContextCompat.getDrawable(context,R.drawable.ic_sort_up);Drawable drawableUp= DrawableCompat.wrap(up);DrawableCompat.setTint(drawableUp, ContextCompat.getColor(context,R.color.theme));image.setImageDrawable(drawableUp);
第二种只能在API21以上使用
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ImageView image = new ImageView(context); image.setImageResource(R.drawable.ic_sort_down); image.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(context,R.color.theme)));}
更多相关文章
- 应用内版本更新库UpdateVersion
- Android 获取未安装的APK图标、版本号、包名等信息
- Android版本检测/自动更新
- Rockchip查看Android SDK版本
- Android 深入研究SQLite实例(一) 之 业务类 sqlite版本管理类
- Android和Linux版本对应
- Android 版本及别名
- android 各个版本介绍(截止2017年)
- Android api对应版本(持续更新)