动态获取R.drawable.xx资源

String imageName = "index_fragmen"+getColor();
final int resId = context.getResources().getIdentifier(imageName, "drawable", context.getPackageName());
if (resId != 0) {
Log.e("mytest", "可以获取到");
holder.btnCoupon.setBackgroundResource(resId);
}

 

 程序猿必读

转载于:https://www.cnblogs.com/longzhongren/p/6228687.html

你可能感兴趣的:(java,移动开发)