Floating action button and white background

前端 未结 3 1263
青春惊慌失措
青春惊慌失措 2020-12-16 03:21

In fact, I search a way to mimic the FAB\'s inbox. When user press the red button, an opac view and a menu should appear. Because images are more more meaningful, see the fo

3条回答
  •  甜味超标
    2020-12-16 03:40

    I achieved the effect you just mentioned by the following method. I just added a view behind the floating button and above the other layouts, and keep the view visibility GONE, until the menu is expanded. Then i set the view visibility to VISIBLE. And yes i set the background of the view to any opaque color you want.

    My code

    My XML file

    
    
    
    
    
    
    
    
        
    
    
    

    And at the Activity or Fragment where the FloatingButtons are handled

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        setFloatingButtonControls();
    }
    
    private void setFloatingButtonControls(){
        this.bckgroundDimmer = findViewById(R.id.background_dimmer);
        this.floatingActionsMenu = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
        this.floatingActionsMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
            @Override
            public void onMenuExpanded() {
                bckgroundDimmer.setVisibility(View.VISIBLE);
            }
    
            @Override
            public void onMenuCollapsed() {
                bckgroundDimmer.setVisibility(View.GONE);
            }
        });
    }
    

    This will give the effect you wanted. Hope this helps. It sure helped me. :)

提交回复
热议问题