android: dynamically change FAB(Floating Action Button) icon from code

Hirdesh Vishwdewa

How to change FAB icon in an Activity during runtime. I have this code ->

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fabMainActivity);

I know this is possible using fab.setBackgroundDrawable(); but i am a newbie to android, don't understand how to do this.

Any help will be highly appreciated.

Thanks

Sunny

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));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Change android:icon dynamically

From Dev

android Floating Action Button change view anchor dynamically

From Dev

Change the icon dynamically in android notification

From Dev

Change the icon dynamically in android notification

From Dev

MFC Ribbon: change icon of a button (dynamically)

From Dev

Android Floating Action button : Resize inside icon

From Dev

Want to change action bar icon when click on ok button of AlertDialog in Android Studio

From Dev

Android: Navigation Drawer Layout Dynamically change icon

From Dev

Dynamically change header button icon on page change, jQuery mobile 1.4.5

From Dev

Dynamically change Font Awesome Icon on Radio Button Change Event

From Dev

Dynamically change header button icon on page change, jQuery mobile 1.4.5

From Dev

Changing Plugin Action Icon from code

From Dev

Changing Plugin Action Icon from code

From Dev

How change action icons dynamically in android wear

From Dev

How change action icons dynamically in android wear

From Dev

Change Android Drawable Button Icon Programmatically

From Dev

How to Change checkBox button icon in Android?

From Dev

Is it possible ro change the floating action button label to right of icon

From Dev

Change the button icon from bootstrap is not working

From Dev

How Can I set Action bar button icon by Java code

From Dev

How can we change android application icon dynamically in Android

From Dev

How can we change android application icon dynamically in Android

From Dev

Change background of the button in Action Bar, Android

From Dev

Android: Create bigger Floating Action Button with bigger icon

From Dev

Change switch icon color from java code

From Dev

can't change action menu icon in android app

From Dev

How to add/change an Android Studio toolbar icon to an action?

From Dev

android change color of an icon from EditText

From Dev

Change Icon on button press

Related Related

  1. 1

    Change android:icon dynamically

  2. 2

    android Floating Action Button change view anchor dynamically

  3. 3

    Change the icon dynamically in android notification

  4. 4

    Change the icon dynamically in android notification

  5. 5

    MFC Ribbon: change icon of a button (dynamically)

  6. 6

    Android Floating Action button : Resize inside icon

  7. 7

    Want to change action bar icon when click on ok button of AlertDialog in Android Studio

  8. 8

    Android: Navigation Drawer Layout Dynamically change icon

  9. 9

    Dynamically change header button icon on page change, jQuery mobile 1.4.5

  10. 10

    Dynamically change Font Awesome Icon on Radio Button Change Event

  11. 11

    Dynamically change header button icon on page change, jQuery mobile 1.4.5

  12. 12

    Changing Plugin Action Icon from code

  13. 13

    Changing Plugin Action Icon from code

  14. 14

    How change action icons dynamically in android wear

  15. 15

    How change action icons dynamically in android wear

  16. 16

    Change Android Drawable Button Icon Programmatically

  17. 17

    How to Change checkBox button icon in Android?

  18. 18

    Is it possible ro change the floating action button label to right of icon

  19. 19

    Change the button icon from bootstrap is not working

  20. 20

    How Can I set Action bar button icon by Java code

  21. 21

    How can we change android application icon dynamically in Android

  22. 22

    How can we change android application icon dynamically in Android

  23. 23

    Change background of the button in Action Bar, Android

  24. 24

    Android: Create bigger Floating Action Button with bigger icon

  25. 25

    Change switch icon color from java code

  26. 26

    can't change action menu icon in android app

  27. 27

    How to add/change an Android Studio toolbar icon to an action?

  28. 28

    android change color of an icon from EditText

  29. 29

    Change Icon on button press

HotTag

Archive