2014-10-09 74 views
1

我利用股票抽屜式導航活動舉辦了一系列的片段。我試圖在更改爲導航抽屜中的不同片段時實現單獨的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> 

回答

0

這篇文章幫助解決了我問題

Action buttons doesn't show up on Action Bar?

我改變了我的XML看起來像這樣

<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"/> 

2

你應該將setHasOptionsMenu(真)到的onCreate()的片段的方法

+0

我的片段中實現的OnCreate(),並把setHasOptionsMenu(真)後,它已導致相同的行爲以前上市。 - 選項菜單在「溢出/三重點」菜單中更改。 「 – 2014-10-09 16:42:30