bitmap - Android CardView setBackground as BitmapDrawable when API <21 -


i have problem when trying setbackground() of cardview programatically in kitkat.when application running on android l there no problem in code :

drawable drawable = new bitmapdrawable(appcontext.getresources(), bitmap); if (cardview != null) {                     cardview.setbackground(drawable); } 

but when runs in api older android l error: android.graphics.drawable.bitmapdrawable cannot cast android.support.v7.widget.roundrectdrawablewithshadow.

i found out known issue , there work around want set colour background of card, there solution set bitmap background programatically? have idea how create roundrectdrawablewithshadow bitmapdrawable?

do have idea how create roundrectdrawablewithshadow bitmapdrawable?

don't unless wish rewrite own cardview implementation.

roundrectdrawablewithshadow package private class used take color supplied app:cardbackgroundcolor or setcardbackgroundcolro(int) , wrap in rounded rectangle shadow produce drawable.

since elevation introduced in api 21 shadow painted part of cardview background drawable on prior platforms you can't set own background via setbackground(*).

is there solution set bitmap background programatically?

you put view, *layout, etc. in card , set rounded drawable background on it. not effective performance-wise though.

https://developer.android.com/reference/android/support/v4/graphics/drawable/roundedbitmapdrawable.html


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -