美文网首页
Android dataBinding引用mipmap文件夹下的

Android dataBinding引用mipmap文件夹下的

作者: hao_developer | 来源:发表于2021-11-17 12:05 被阅读0次

Android dataBinding引用mipmap文件夹下的资源文件

1、首先在布局中导入如下两个包(注意包名)

<import type="com.xxx.xxx.R" />
<import type="androidx.core.content.ContextCompat" />

2、然后在需要引用mipmap文件的相应view下添加mipmap文件,我用的是ImageView,示例如下:

 <ImageView
    android:layout_width="15dp"
    android:layout_height="15dp"
    android:src="@{ContextCompat.getDrawable(context,likeStatus == 1 ? R.mipmap.zan_orange :R.mipmap.zan)}"
   tools:src="@mipmap/zan" />

\color{red}{ tools:src}\默认显示的图片

相关文章

网友评论

      本文标题:Android dataBinding引用mipmap文件夹下的

      本文链接:https://www.haomeiwen.com/subject/pkeltrtx.html