android - How do I get Bitmap from a TransitionDrawable -


i have transitiondrawable bitmap need. when use getcurrent() drawable, apparently result still transitiondrawable. truth transitiondrawable created in class using

final transitiondrawable td = new transitiondrawable(new drawable[] {   new colordrawable(android.r.color.transparent), drawable }); 

where drawable bitmapdrawable. if try cast as

bitmap bmp = (bitmapdrawable) transitiondrawable.getcurrent(); 

then class cast exception.

for context, transitiondrawable in line 378 of imageworker of bitmapfun.

transitiondrawable inherits layerdrawable can use finddrawablebylayerid(int id) specific drawable.

example: using btn_toggle_bg.xml android sources (4.4.1)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+android:id/background" android:drawable="@android:drawable/btn_default_small" /> <item android:id="@+android:id/toggle" android:drawable="@android:drawable/btn_toggle" /> </layer-list> 

and assuming acquired in transitiondrawable object:

drawable d = transitiondrawable.finddrawablebylayerid( android.r.id.background ); 

the background id defined android, that's why r scoped android. if created id in own app <item android:id="@+id/mylayerid" ... , find .finddrawablebylayerid( r.id.mylayerid );

when build transition drawable in code need assign each drawable .

transitiondrawable.setdrawablebylayerid( android.r.id.background, new colordrawable(..) ); 

if id doesn't exist, added layer id.

hope helps


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -