在我的应用中,我正在尝试将位图图像设置为FrameLayout
,其中图像来自SQLite
数据库。我正在解码该图像,将其转换为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);
我正在使用,,
android:minSdkVersion="14"
android:targetSdkVersion="19"
答案 0 :(得分:4)
setBackground()
方法已添加到API级别16.使用setBackgroundDrawable()
代替......
Drawable imagebakground = new BitmapDrawable(getResources(),Imagebackground);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
framelayout.setBackground(imagebakground);
} else {
frameLayout.setBackgroundDrawable(imagebakground);
}
答案 1 :(得分:2)
setBackground()
,因此将minSdkVersion设置为14无效。您正在测试它的设备必须至少达到api级别
答案 2 :(得分:2)
将Bitmap
设为BackgroundDrawable
至Layout
而不是setBackground()
if (Build.VERSION.SDK_INT >= 16)
your_layout.setBackground(...);
else
your_layout.setBackgroundDrawable(...);
它的becoz setBackground()
可从API Level 16获得