在我的应用程序中,我试图将位图图像设置为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"发布于 2014-03-12 12:02:58
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);
}发布于 2014-03-12 12:02:47
setBackground()可以从API 16中获得,因此将minSdkVersion设置为14无助于此。您正在测试它的设备,至少必须是api级别。
发布于 2014-03-12 12:02:56
将Bitmap设置为BackgroundDrawable到您的Layout而不是setBackground()
if (Build.VERSION.SDK_INT >= 16)
your_layout.setBackground(...);
else
your_layout.setBackgroundDrawable(...);这是因为API级别16提供了setBackground()
https://stackoverflow.com/questions/22350868
复制相似问题