Create an Actionbar OptionsMenu in an PreferenceFragment

北城余情 提交于 2019-12-13 01:29:21

问题


I run into a problem while I was settings up the Preferences for my App.

I would like to have a Button in the ActionBar (e.g. Save) but my ActionBar is not showing anything. I put this Line in the onCreate Method:

this.setHasOptionsMenu(true);

And implemented the

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
public boolean onOptionsItemSelected(MenuItem item)

methods as well. However, it does not show anything.


回答1:


Be sure your button item in your action menu layout something like:

<item
    android:id="@+id/action_save"
    android:orderInCategory="1"
    your_icon:showAsAction="always"
    android:icon="@drawable/icon_save"
   />



来源:https://stackoverflow.com/questions/23754483/create-an-actionbar-optionsmenu-in-an-preferencefragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!