[英]Actionbar Buttons not showing up on Fragment change
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.
当我从导航抽屉中更改为不同的片段时,我正在尝试实现单独的ActionBar按钮。
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 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 菜单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>
您应该将setHasOptionsMenu(true)移到片段的onCreate()方法中
This post helped solve my problem 这篇文章帮助解决了我的问题
Action buttons doesn't show up on Action Bar? 动作按钮没有显示在动作栏上?
I changed my xml to look like this 我将我的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"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.