0

I am using this circular menu for my App. https://github.com/oguzbilgener/CircularFloatingActionMenu It is working. But when i open my Navigation Drawer. This Menu is in the front. How can i make the Menu to go Back to the Navigation Drawer.

How Can i Bring my Navigation Drawer to Front ?

enter image description here

public class Home extends MainActivity implements OnClickListener
{


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        this.application = (Remtt) this.getApplication();
        this.preferences = this.application.getPreferences();
        super.onCreate(savedInstanceState);
        this.checkOnCreate();

            int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size);
            int redActionButtonMargin = getResources().getDimensionPixelOffset(R.dimen.action_button_margin);
            int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
            int redActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_margin);
            int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius);
            int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
            int blueSubActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);

            ImageView fabIconStar = new ImageView(this);
            fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));

            FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMargin, redActionButtonMargin);
            fabIconStar.setLayoutParams(starParams);

            FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(redActionButtonContentSize, redActionButtonContentSize);
            fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin);

            FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this).setContentView(fabIconStar, fabIconStarParams).setBackgroundDrawable(R.drawable.button_action_red_selector).setPosition(FloatingActionButton.POSITION_TOP_CENTER).setLayoutParams(starParams).build();

            // Set up customized SubActionButtons for the right center menu
            SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
            lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));

            FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
            blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
            lCSubBuilder.setLayoutParams(blueContentParams);
            // Set custom layout params
            FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize, blueSubActionButtonSize);
            lCSubBuilder.setLayoutParams(blueParams);

            ImageView lcIcon1 = new ImageView(this);
            ImageView lcIcon2 = new ImageView(this);
            ImageView lcIcon3 = new ImageView(this);
            ImageView lcIcon4 = new ImageView(this);
            ImageView lcIcon5 = new ImageView(this);
            ImageView lcIcon6 = new ImageView(this);
            ImageView lcIcon7 = new ImageView(this);
            ImageView lcIcon8 = new ImageView(this);
            ImageView lcIcon9 = new ImageView(this);

            lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.anim));
            lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.anim));
            lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.anim));
            lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.anim));
            lcIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
            lcIcon6.setImageDrawable(getResources().getDrawable(R.drawable.anim));
            lcIcon7.setImageDrawable(getResources().getDrawable(R.drawable.anim));
            lcIcon8.setImageDrawable(getResources().getDrawable(R.drawable.anim));
            lcIcon9.setImageDrawable(getResources().getDrawable(R.drawable.anim));

            // Build another menu with custom options
            FloatingActionMenu leftCenterMenu = new FloatingActionMenu.Builder(this).addSubActionView(lCSubBuilder.setContentView(lcIcon1, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon2, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon5, blueContentParams).build())
                    .addSubActionView(lCSubBuilder.setContentView(lcIcon6, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon7, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon8, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon9, blueContentParams).build()).setRadius(redActionMenuRadius).setStartAngle(0).setEndAngle(360).attachTo(leftCenterButton).build();
        }
    }
}
Arulnadhan
  • 923
  • 4
  • 17
  • 46
  • use method bringtofront() or use framelayout. – Yogendra Dec 26 '14 at 03:15
  • 1
    Modify the library. Change the method FloatingActionMenu.getActivityContentView() and return the viewgroup that holds your activity content - the one defined inside DrawerLayout tags in xml. – Athena Dec 29 '14 at 09:15
  • http://stackoverflow.com/questions/27067440/my-fragment-hides-the-navigation-drawer – Mike M. Dec 29 '14 at 11:52
  • @MikeM. It was very useful. How can i pass the Viewgroup from my Activity to this method setContainerView()? – Arulnadhan Dec 30 '14 at 13:59
  • It should be the content ViewGroup in your DrawerLayout. That is, the first thing listed within the DrawerLayout; usually a FrameLayout. For example: `FrameLayout container = (FrameLayout) findViewById(R.id.content);`. If you need more specifics, you'll have to post your Activity's layout xml. – Mike M. Dec 30 '14 at 14:08
  • Post the layout of the `Activity`. – Xaver Kapeller Jan 02 '15 at 18:14
  • I think you are adding the floating navigation bar to the activity rather than the framelayout of the fragment .Can you post the XML file of the activity – D V Ramana Jan 03 '15 at 11:23

1 Answers1

0

This is very similar to my answer here, with only minor changes to the FloatingActionButton instantiation.

The library code assumes that the Button and Menu are to appear on top of an Activity's content View, and everything therein. The addition of a container ViewGroup member in the FloatingActionButton class allows us to specify a child ViewGroup to be the parent instead. Please note that the following changes will only work if a FloatingActionButton is used with the Menu.

The additions to the FloatingActionButton class:

public class FloatingActionButton extends FrameLayout {
    ...
    private ViewGroup containerView;
    ...
    public FloatingActionButton(Activity activity, 
                                LayoutParams layoutParams, 
                                int theme,
                                Drawable backgroundDrawable,
                                int position,
                                View contentView,
                                FrameLayout.LayoutParams contentParams      
                                // Note the addition of the following
                                // constructor parameter here
                                , ViewGroup containerView) {
        ...
        setClickable(true);

        // This line is new. The rest of the constructor is the same.
        this.containerView = containerView;     

        attach(layoutParams);
    }
    ...
    public View getActivityContentView() {
        if(containerView == null) {
            return ((Activity)getContext())
                .getWindow().getDecorView().findViewById(android.R.id.content);
        } else {
            return containerView;
        }
    }

    public ViewGroup getContainerView() {
        return containerView;
    }

    // The following setter is not strictly necessary, but may be of use
    // if you want to toggle the Button's and Menu's z-order placement
    public void setContainerView(ViewGroup containerView) {
        this.containerView = containerView;
    }
    ...
    public static class Builder {
        ...
        private ViewGroup containerView;
        ...
        public Builder setContainerView(ViewGroup containerView) {
            this.containerView = containerView;
            return this;
        }

        public FloatingActionButton build() {
            return new FloatingActionButton(activity,
                                            layoutParams,
                                            theme,
                                            backgroundDrawable,
                                            position,
                                            contentView,
                                            contentParams,
                                            // New argument
                                            containerView);
        }
    }
    ...
}

And the changes to the FloatingActionMenu class:

public class FloatingActionMenu {
    ...
    public View getActivityContentView() {
        if(mainActionView instanceof FloatingActionButton && 
            ((FloatingActionButton) mainActionView).getContainerView() != null) {
            return ((FloatingActionButton) mainActionView).getContainerView();
        } else {
            return ((Activity)mainActionView.getContext())
                .getWindow().getDecorView().findViewById(android.R.id.content);
        }
    }
    ...
}

Then, assuming your Activity's layout is similar to:

<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ...>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    ...
</android.support.v4.widget.DrawerLayout>

In your Home Activity, you would build and instantiate leftCenterButton like so:

public class Home extends Activity implements OnClickListener {
    ...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        FrameLayout container = (FrameLayout) findViewById(R.id.container);

        FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this)
            .setContentView(fabIconStar, null)
            .setBackgroundDrawable(R.drawable.ic_launcher)
            .setPosition(FloatingActionButton.POSITION_TOP_CENTER)
            .setLayoutParams(starParams)
            // The new method call is added here
            .setContainerView(container)
            .build();
        ...
    }
    ...
}
Community
  • 1
  • 1
Mike M.
  • 38,532
  • 8
  • 99
  • 95