1

I am utilizing the stock Navigation Drawer Activity to host a series of fragments. I am trying to implement seperate ActionBar Buttons when I change to different fragments from within the navigation drawer.

I am running into an issue where the items are not being added to the actionbar directly and are instead being added to the "triple dot" overflow menu as a drop down selection.

What am I doing wrong that the buttons are not becoming available on the actionbar?

JOBFRAGMENT

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_jobs, container, false);
    return view;

}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Add your menu entries here
    //inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.job_navigation, menu);
    super.onCreateOptionsMenu(menu, inflater);
}

MENU XML

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_drawer"
    android:showAsAction="ifRoom"
    android:title="@string/action_search"/>
</menu>
Coova
  • 1,818
  • 5
  • 36
  • 63

2 Answers2

2

You should move setHasOptionsMenu(true) to the onCreate() method of your fragment

Aurélien Guillard
  • 1,203
  • 8
  • 20
  • After implementing OnCreate() within my Fragment, and placing setHasOptionsMenu(true), it has resulted in the same behavior as previously listed. -- The option menu is changed within the "overflow/triple dot" menu. " – Coova Oct 09 '14 at 16:42
0

This post helped solve my problem

Action buttons doesn't show up on Action Bar?

I changed my xml to look like this

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" >

<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_drawer"
    android:title="@string/action_search"
    app:showAsAction="always"/>

Community
  • 1
  • 1
Coova
  • 1,818
  • 5
  • 36
  • 63