简体   繁体   中英

Create an Actionbar OptionsMenu in an PreferenceFragment

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 (eg 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM