material design - android: dynamically change FAB(Floating Action Button) icon from code -
how change fab icon in activity during runtime. have code ->
floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fabmainactivity);   i know possible using fab.setbackgrounddrawable(); newbie android, don't understand how this.
any highly appreciated.
thanks
changing floatingactionbutton source:
if (build.version.sdk_int >= build.version_codes.lollipop) {             floatingactionbutton.setimagedrawable(getresources().getdrawable(r.drawable.ic_full_sad, context.gettheme()));         } else {             floatingactionbutton.setimagedrawable(getresources().getdrawable(r.drawable.ic_full_sad));     }   this can replaced following code support library instead:
floatingactionbutton.setimagedrawable(contextcompat.getdrawable(getcontext(), r.drawable.ic_full_sad));      
Comments
Post a Comment