Home > android, ui > Customizing AlertDialog, an update – removing the title

Customizing AlertDialog, an update – removing the title

A follow-up to an earlier post about customizing AlertDialog.

Jonas Petersson asked whether it’s possible to remove an alert dialog’s title. It is. Add a call to requestWindowFeature in your subclass’s onCreate, make sure it comes before the call to super.onCreate():

	protected void onCreate(Bundle savedInstanceState) {


		/*** This removes the title ***/


And this is what it looks like:

Categories: android, ui
  1. E.Sarmas
    March 17, 2011 at 3:58 pm

    Kudos for your blog. Very nice indeed!

    Reading this post and a few others, I have a feeling that
    you prefer to use android “Dialogs” instead of “Activities” for popup
    user dialogs (of course I may be wrong).
    I think this increases the size of your code and makes the
    program logic more complex.
    What can you comment on the relative merits of using
    Dialogs vs Activities ?

    • Kostya Vasilyev
      March 17, 2011 at 6:07 pm

      Yes, I prefer using dialogs, specifically, subclasses of AlertDialog, to be able to get that cool look with the icon in the title bar and the grey (on my devices) panel behind the buttons along the bottom.

      As for it being more complex, yes, I found that using alert dialogs requires a few lines of supporting code here and there, but it’s not really much.

  2. Jonas Petersson
    February 27, 2011 at 4:25 pm

    BTW: I’ve also tried the setCustomTitle() route, in the hope that I would be able to set a 1×1 pixel title, but it appears that the height is fixed – all I can do is alter the content. If I could instantiate the AlertDialog (bypassing the builder) the requestWindowFeature() might be useful…
    For the record: the best workaround for the 3.0 issue I’ve found is to fiddle the dialog layout flags when the loading is done. I’m starting to suspect that the error is really in the FrameLayout as I can sometimes see both members mixed. Explicitly killing the throbber animation seems to lessen the system load.

  3. Jonas Petersson
    February 27, 2011 at 1:40 pm

    Yes, I’m aware at it can be hidden (as opposed to removed) as such, but it still take up the same space. It is not so obvious when the dialog is small as in your example, but if you look carefully, you can tell that the vertical centering considers the title “invisible” rather than “gone”. When you push it to full screen height you will see this much clearer.

    Hence, for my “almost full screen” web dialog (example apk in my original post) using AlertDialog doesn’t look they way it should IMHO.

    If you know of a workaround for this, I’d be in your debt…

    Best / Jonas

    • Kostya Vasilyev
      February 27, 2011 at 3:44 pm

      Ah. See what you mean.

      You might want to look at the source for AlertDialog, see if you can find a way to adjust things.

      Unfortunately, the view IDs used there are internal (not accessible though android.R.id.*), so you might need to navigate the view hierarchy yourself.

      The real answer is for the platform to provide an AlertDialog-themed Activity. Dianne Hackborn mentioned this recently on the mailing list, so hopefully, one day it might show up.

      But wait – if you don’t need the title bar in your dialog, you could just use an Activity with Theme.Dialog. You’d lose the grey background for the button area, but that’s only one of the two (the other difference being the title bar with its icon and separator).

      And since your intent is to run a WebView, then you can put any necessary buttons into the HTML code, it will look even better (seamless).

      • Jonas Petersson
        February 27, 2011 at 4:37 pm

        True, this is a possible route, but it seems like it might involve more code than the raw Dialog() I use right now. After all, it is a dialog I’m after so structurally it makes sense to use a Dialog derivate rather than an Activity in disguise (though I confess that I’ve already done that for my settings).

        Thanks for your suggestions!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s