Search code examples
androidandroid-dialogfragmentandroid-actionbar-compatdialogfragment

Up ActionBar action on DialogFragment


I have a DialogFragment that is styled to full screen using setStyle(STYLE_NORMAL, R.style.Theme_App).

The DialogFragment shows fine but the up action (the homeAsUp action on the ActionBar) does not work. I tried implementing onOptionsItemSelected in the DialogFragment but it is never called.

Is there a way to get the up action callback in the DialogFragment so I can dismiss it ? For reference, I'm using ActionBarCompat.


Solution

  • There is no way to attach an ActionBar to the DialogFragment even though you can set the theme of the DialogFragment it will not register as a ActionBar to it, Dialog.getActionBar() will always return null.

    Instead of getting the ActionBar you can always attach a Layout that will look like an ActionBar and set the functionality on it using menu.

    The other way is to create an activity with actionBar as a Dialog you can refer to this post