"android: dynamically change fab(floating action button) icon from code" Code Answer

2

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 be replaced by following code from the support library instead:

floatingactionbutton.setimagedrawable(contextcompat.getdrawable(getcontext(), r.drawable.ic_full_sad));
By pushkin on August 20 2022

Answers related to “android: dynamically change fab(floating action button) icon from code”

Only authorized users can answer the Search term. Please sign in first, or register a free account.