在ImageView变量中传递可绘制图像

时间:2017-12-28 17:29:21

标签: java android imageview drawable

如何将图像从可绘制文件转换为图像视图 因为这不会起作用

ImageView image= R.drawable.pic;

3 个答案:

答案 0 :(得分:1)

试试这个

ImageView imageview = findViewById(R.id.imageView);
imageview.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.pic));

答案 1 :(得分:0)

试试这个

ImageView image = new ImageView(this);
image.setImageResource(R.drawable.pic);

ImageView image = new ImageView(this);
image.setImageDrawable(getResources().getDrawable(R.drawable.pic));

答案 2 :(得分:0)

试试这个

 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));