How to change background color of floating action menu

白昼怎懂夜的黑 提交于 2019-12-12 04:48:38

问题


I am using this library for floating action button

https://github.com/futuresimple/android-floating-action-button

If anyone is aware about it, we know that we can change the background color of floating action menu with this line in xml :

fab:fab_addButtonColorNormal="@color/floating_action_menu"

Is there a way to do so programmatically??

floatingmenu.setBackgroundColor(color) doesnt work......


回答1:


It looks like FloatingActionsMenu has no getter/setter for this. To get this feature you can fork the project and add getter for mAddButton member of FloatingActionsMenu class:

AddFloatingActionButton getAddButton(){
    return mAddButton;     
}

Then you will be able to call methods of FloatingActionButton class :

floatingmenu.getAddButton().setColorNormal(...); 



回答2:


I got one solution

Add this method in FloatingActionsMenu class :

public void setNormalColor(int color) {
        mAddButtonColorNormal = color;
        removeView(mAddButton);
        createAddButton(myContext);
    }

It's works for me



来源:https://stackoverflow.com/questions/30099725/how-to-change-background-color-of-floating-action-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!