Here is snippet to set background in Imageview that support API 7 / 8 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Set background image * * @param imagePath */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @SuppressWarnings("deprecation") private void setBackgroundImage(final String imagePath) { Bitmap bm = openAndResize(); Drawable drawable = new BitmapDrawable(getApplication().getResources(), bm); int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { previewImageView.setBackgroundDrawable(drawable); } else { previewImageView.setBackground(drawable); } } |