简体   繁体   中英

Android - how to implement nested button

I am working on a project that has 5 buttons when I click on any of them it should show another 3 buttons. When I click on any of the 3 buttons it should open an activity.

I have tried working with MaterialArcMenu it doesn't give me what I need it gave me a circle button .

Can I receive any advice on this?

Button 1 ---> Nested Button 1 --> Nested Button 1

     ---> Nested Button 2    

Button 2

Button 3

Button 4

Button 5

在此输入图像描述

  1. Have 8 buttons in your xml file. 5 of which are visible, 3 of which are hidden & disabled
  2. Have the 5 implement the same onClickListener (using xml onClick attribute is easiest for this)
  3. Have the 3 implement the same onClickListener as well (using xml onClick attribute is easiest for this)
  4. In the onClickListener for the 5 buttons, write code that makes the other 3 buttons visible & enabled
  5. In the onClickListener for the 3 buttons, write code that opens the new activity

If you are creating the button from a layout, then what I would suggest to do is add the activity or fragment as the click event listener. Secondly, set a tag for the button. Then when the button is clicked, get the tag for the view and handle accordingly.

Here is an example:

 protected CustomImageButton getSmartLinkImageButton(int buttonImageResource, int colorToChangeTo,  boolean isLargerImage, ActionType buttonAction) {
        LayoutInflater inflater = (LayoutInflater) this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        SmartLinkImageButton button = (SmartLinkImageButton) inflater.inflate(R.layout.footer_smartlink_image_button, null);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mFooterButtonWidth, 
                isLargerImage == true ? mFooterButtonHeight / 2 : mFooterButtonHeight);
        params.gravity = Gravity.CENTER;
        button.setLayoutParams(params);

        if(isLargerImage) 
            button.setScaleType(ScaleType.FIT_CENTER);
        button.setImageResource(buttonImageResource);

        if(colorToChangeTo > 0) {
            changeImageViewImageColor(button, null, colorToChangeTo);
            button.setDefaultColorFilter(colorToChangeTo);
        }

        button.setTag(buttonAction); //HERE IS THE TAG CREATION
        button.setOnClickListener(this);

        //optional method for mapping image buttons
        mapImageButton(button, buttonAction);

        inflater = null;
        return button;
    }

Then the onClick:

@Override
public void onClick(View view) {            
    view.getTag(); //DO ACTION BASED ON VIEWS TAG
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM