Hello all..

Today I will show you how to align the message text to center in an AlertDialog. By default it is left aligned, so we have to get a reference to it to align it to center.This is how we do it.

Android Alert Dialog

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("My Title");
        builder.setMessage("CoderzHeaven, Heaven of all working codes.");
        builder.setPositiveButton("OK", null);
        AlertDialog dialog = builder.show();
        TextView messageText = dialog.findViewById(android.R.id.message);

Please leave your valuable comments on this post.



  1. Sujay U N January 10, 2018 at 1:03 pm

    android.R.id.message works good for Message.

    What is theandroid.R.id. for Title and List Items

    • James January 10, 2018 at 3:08 pm

      You can check this link for more


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.