以编程方式将 mipmap 图像设置为 linearLayout 背景
Set mipmap image as linearLayout background programmatically
我在 mipmap
目录中有一张 .png
图片。知道我想以编程方式将此图像设置为 linearLayout
背景。并在一些过程后将其删除。
target SDK : 23
min SDK : 14
我应该使用哪个功能?
这可以改变背景颜色:
ll.setBackgroundColor(getResources().getColor(R.color.color_mtn));
但是背景图片在哪里?
ll.setBackgroundResource(R.mipmap.my_image);
或
ll.setBackground(ResourcesCompat.getDrawable(getResources(), R.mipmap.my_image, null))
两者都在工作
iv_pic_image.setImageResource(R.mipmap.generic_product_4);
or
iv_pic_image.setImageDrawable(getResources().getDrawable(R.mipmap.generic_product_4));
我在 mipmap
目录中有一张 .png
图片。知道我想以编程方式将此图像设置为 linearLayout
背景。并在一些过程后将其删除。
target SDK : 23
min SDK : 14
我应该使用哪个功能?
这可以改变背景颜色:
ll.setBackgroundColor(getResources().getColor(R.color.color_mtn));
但是背景图片在哪里?
ll.setBackgroundResource(R.mipmap.my_image);
或
ll.setBackground(ResourcesCompat.getDrawable(getResources(), R.mipmap.my_image, null))
两者都在工作
iv_pic_image.setImageResource(R.mipmap.generic_product_4);
or
iv_pic_image.setImageDrawable(getResources().getDrawable(R.mipmap.generic_product_4));