Custom dialog on Android: How can I center its title?


I’m developing an Android application.

How can I center the title for a custom dialog that I’m using?


Just found this post while trying to figure out how to do the same thing. Here’s how I did it for anyone else that finds this in the future.

Style xml is as follows:

    <?xml version="1.0" encoding="utf-8"?>
        <style name="PauseDialog" parent="@android:style/Theme.Dialog">
            <item name="android:windowTitleStyle">@style/PauseDialogTitle</item>

        <style name="PauseDialogTitle" parent="@android:style/TextAppearance.DialogWindowTitle">
            <item name="android:gravity">center_horizontal</item>
        <style name="DialogWindowTitle">
        <item name="android:maxLines">1</item>
        <item name="android:scrollHorizontally">true</item>
        <item name="android:textAppearance">@android:style/TextAppearance.DialogWindowTitle</item>

And in my activities onCreateDialog method for the dialog I want styled I create the dialog like this:

Dialog pauseDialog = new Dialog(this,;

Answered By – ChrisJD

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published