In the Calendar app on my Galaxy Tab 10.1, when creating a new event a dialog comes up with Done and Cancel buttons in the title bar/action bar area.
I'd like to implement this in my app. I've tried using setHasOptionsMenu(true)
in addition to overriding onCreateOptionsMenu
in my DialogFragment
subclass, but my action items do not appear. I've also tried calling getDialog().getActionBar()
from within onCreateView
but it always returns null
.
I am able to get this working if I start an Activity
rather than showing a dialog but that takes up the whole screen. Is there a standard way to do this using a DialogFragment
?
I have spent an incredible amount of time playing around with this. The accepted answer works on a galaxy nexus 7 (Android 4.2), but fails on a samsung galaxy SIII (Android 4.1) and a samsung galaxy tab 10.2 (Android 4.0), with the following exception:
This is caused by code in ActionBarView.onMeasure(int, int) which checks to ensure the layout is set to match_parent. The correct solution is instead set the width of the window via setLayout instead of using the setAttributes.
This is a fixed version of showAsPopup() which works on all devices I have tested under:
For completeness sake, here is the PopupTheme again:
If you are using ActionBarSherlock, declare the theme as below:
And, initialize a SherlockActivity with PopupTheme according to Luke Sleeman's answer.
Result: