以下方法纯个人所学Android开发积累,可能还有其他的方法,欢迎各位补充:
方法一:
private Resources resources;//获取本地资源.
.前面是声明部分,下面开始使用
.
resources= context.getResources();
Drawable btnDrawable = resources.getDrawable(R.drawable.power1);这样就可以得到本地资源中的图片Drawable对象了。
方法二:
private Drawable dd; private int delIconId = R.drawable.scan2;//得到本地资源中图片的id
.
.前面也是声明部分,下面开始使用
.
dd= ContextCompat.getDrawable(this,delIconId);
这样也可以得到本地资源中的图片对象。