如何获取res下drawable文件夹中的图片

来源:互联网 发布:php array diff keys 编辑:程序博客网 时间:2024/05/20 23:33

以下方法纯个人所学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);

这样也可以得到本地资源中的图片对象。

阅读全文
0 0
原创粉丝点击