动态获取R.drawable.xx资源

Posted 龙种人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态获取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);
                    }

 

以上是关于动态获取R.drawable.xx资源的主要内容,如果未能解决你的问题,请参考以下文章