如果ImageView具有背景可绘制,如何比较它

问题描述 投票:-2回答:1

if(imageview == R.drawable.example){

}

android kotlin
1个回答
0
投票

希望此功能对您有帮助:

public static boolean checkImageResource(Context ctx, ImageView imageView,
    int imageResource) {
boolean result = false;

if (ctx != null && imageView != null && imageView.getDrawable() != null) {
    ConstantState constantState;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        constantState = ctx.getResources()
                .getDrawable(imageResource, ctx.getTheme())
                .getConstantState();
    } else {
        constantState = ctx.getResources().getDrawable(imageResource)
                .getConstantState();
    }

    if (imageView.getDrawable().getConstantState() == constantState) {
        result = true;
    }
}

return result;
}
© www.soinside.com 2019 - 2024. All rights reserved.