1.将Bitmap影像到FrameLayout,我解码的图像转换成 Drawable ,然后将其设置为背景的 FrameLayout java.lang.NoSuchMethodError: android.widget.FrameLayout.setBackground() ByteArrayInputStream imageStream2= new ByteArrayInputStream(cardbackground); Bitmap Imagebackground = BitmapFactory.decodeStream(imageStream2); Drawable imagebakground=new BitmapDrawable(getResources(),Imagebackground); framelayout.setBackground(imagebakground);
解决方法:setBackground()方法,在添加 API 级别 16。使用 setBackgroundDrawable()相反用setBackground
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { framelayout.setBackground(imagebakground); } else { frameLayout.setBackgroundDrawable(imagebakground); }
时间: 2024-11-07 23:35:40