snapshot
[1]: http://i.stack.imgur.com/P0uHw.png
please help how to show overflow menu in fragment.my code below
this is my fragment code:.,,.,.,.,.,.,.,
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_main, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
this is my menu 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"
xmlns:myapp="http://schemas.android.com/tools"
>
<item
android:id="@+id/addContactItemId"
android:title="@string/addContact"
android:orderInCategory="101"
myapp:showAsAction="ifRoom|withText"
/>
请帮助我。提前谢谢。我看到了一些教程,其中默认创建了溢出菜单,但它是用于活动,但我正在尝试片段中的溢出菜单。请帮助
答案 0 :(得分:1)
对于您想要菜单的特定片段,您的代码中是否有setHasOptionsMenu(true)?
像...一样的东西。
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
必须告诉您的片段它有一个选项菜单,否则它不会尝试给它充气。