Reputation: 1
how to convert an image from drawable file to an Image view because this won't work
ImageView image= R.drawable.pic;
Upvotes: 0
Views: 156
Reputation: 1091
Try this
ImageView image = new ImageView(this);
image.setImageResource(R.drawable.pic);
or
ImageView image = new ImageView(this);
image.setImageDrawable(getResources().getDrawable(R.drawable.pic));
Upvotes: 0
Reputation: 3539
Try this
ImageView imageview = findViewById(R.id.imageView);
imageview.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.pic));
Upvotes: 1
Reputation: 8272
Try this
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
fab.setImageDrawable(getResources().getDrawable(R.drawable.pic,this.getTheme()));
}else {
fab.setImageDrawable(getResources().getDrawable(R.drawable.pic));
Upvotes: 0