Android dataBinding引用mipmap文件夹下的

2021-11-17  本文已影响0人  hao_developer

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}\默认显示的图片

上一篇 下一篇

猜你喜欢

热点阅读