1

I'm trying to follow the answers of this question: Cancel Done buttons in Calendar App - Is it part of Action Bar? I want to do create that custom action bar

I'm noob on Android, so my questions are: I have to code a Fragment? How can I do this? I created a method to set the custom bar, I'm calling at onCreateView, it's not working...The action bar doesn't appears.

    private void createCustomActionBar(){
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View actionBarButtons = inflater.inflate(R.layout.custom_action_bar,
                new LinearLayout(MyActivity.this), false);
        View cancelActionView = actionBarButtons.findViewById(R.id.action_cancel);
        cancelActionView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                try {
                    processForm();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        View doneActionView = actionBarButtons.findViewById(R.id.action_done);
//        doneActionView.setOnClickListener();
        this.getActionBar().setCustomView(actionBarButtons);
    }

I already copied the xml's, color, drawables from the github's project.

Community
  • 1
  • 1
Lücks
  • 3,806
  • 2
  • 40
  • 54

1 Answers1

0

Looks like you're missing a single line of code before you set the custom ActionBar:

this.getActionBar().setDisplayShowCustomEnabled(true);

See the documentation.

Set whether a custom view should be displayed, if set.

Darwind
  • 7,284
  • 3
  • 49
  • 48