0

This is very similar to many question already posted on stackoverflow, but I still haven't found the right solution. The problem I'm facing is how to implement a custom actionbar.xml file and add a navigation drawer function to the top left icon.

I'm trying to create an action bar that looks like this with two ImageButtons on side and an ImageView as a logo in the center. When user presses on the left ImageButton from actionbar.xml, I would like navigation drawer coming from the left, like in this tutorial. The last thing that troubles me, is how to put a title of pressed fragment in the center of the action bar instead of a logo.

I've already written all xml and java files, but I just can't put the pieces together. Please help.

Community
  • 1
  • 1
Matthew
  • 11
  • 5
  • Read this (http://www.vogella.com/tutorials/AndroidActionBar/article.html) guide to the ActionBar. It also explains the compatibility issues. Swe you still have problems you put your code –  Aug 28 '14 at 11:10
  • i've already read this and I didn't found my answer – Matthew Aug 28 '14 at 11:19

1 Answers1

0

I believe you have solution to create navigation drawer.

Now for your question HOW TO CREATE A CUSTOM ACTION BAR

Try like this ..

    actionBar = getSupportActionBar(); // Get Action Bar reference.

        actionBar.setCustomView(R.layout.action_bar_confirm_cabs); Set your action bar view like this

        fare_ll = (TextView) actionBar.getCustomView().findViewById(R.id.fare_ll); Get id of your custom view like this ...

        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); // Set property for Custom view like this.

fare_ll.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });

That's it.... You are good to go.

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
  • Didn't help. How can I modify the code from navigation drawer tutorial to get a custom action bar from xml file. – Matthew Aug 28 '14 at 11:45
  • Just create and add custom xml layout as I defined. Now if you need to call Navigation Drawer then simply put Navigation Drawer code in your btn onClick event. – AndroidHacker Aug 28 '14 at 11:50
  • Thanks I manage it to work :) but now I have another [**question**](http://stackoverflow.com/questions/25566027/navigation-drawer-with-expandable-listview) – Matthew Aug 29 '14 at 10:07
  • For your query you just need to implement expandable ListView in place of List view. :) – AndroidHacker Aug 30 '14 at 06:59