如何将图像从可绘制文件转换为图像视图 因为这不会起作用
ImageView image= R.drawable.pic;
答案 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));