[英]Android: Button in Actionbar is not showing
I am extending the ActionBarActivity and use fragments in this activity. 我正在扩展ActionBarActivity并在此活动中使用片段。 But the actionbar does not show any button. 但是操作栏没有显示任何按钮。
Here is my code (inside the fragment): 这是我的代码(片段内):
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO Auto-generated method stub
inflater.inflate(R.menu.menu_for_edit_fragments, menu);
super.onCreateOptionsMenu(menu, inflater);
}
And here is the menu_for_edit_fragments.xml: 这是menu_for_edit_fragments.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/item_done"
android:title="@string/done"
app:showAsAction="always"></item>
</menu>
What is wrong here? 这有什么不对?
Try to call setHasOptionsMenu(true) in onCreate() method of the Fragment
. 尝试在Fragment
onCreate()方法中调用setHasOptionsMenu(true) 。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
Did you call setHasOptionsMenu(true)
during your fragment onCreate()
? 您是否在片段onCreate()
期间调用了setHasOptionsMenu(true)
onCreate()
? If you are not, your fragment will not call the onCreateOptionsMenu()
method. 如果不是,则您的片段不会调用onCreateOptionsMenu()
方法。
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.