title: How to stop dialog title text from shrinking when positive button text gets shorter?
body: <p>I want to create an AlertDialog whose title text and message changes each time the user clicks on the positive button as they work through a series of steps.</p>
  
  <p>It all works ok except that when the user gets to the third and final screen the size of the title text shrinks! This appears to be because the string for the positive button's text is shorter for the final screen. If I make it longer the title text no longer shrinks on the final screen.</p>
  
  <p>Here's a stripped down version of my code. <code>dialog.xml</code> layout file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:paddingStart="16dp"
      android:paddingEnd="16dp"
      android:orientation="vertical"&gt;
  
      &lt;TextView
          android:id="@+id/text_view"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMedium"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This is the code for the dialog fragment:</p>
  
  <pre><code>package com.world.test.fixshrinkingdialogtitletext;
  
  import android.annotation.SuppressLint;
  import android.app.AlertDialog;
  import android.app.Dialog;
  import android.content.DialogInterface;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.v4.app.DialogFragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.widget.Button;
  
  public class ChangeTitleDialogFragment
          extends DialogFragment {
  
      private static final String DIALOG_TITLE = "DIALOG_TITLE";
      private static final String TEXT_PROMPT = "TEXT_PROMPT";
      private static final String POSITIVE_BUTTON_TEXT = "POSITIVE_BUTTON_TEXT";
      private static final String SCREEN_COUNT = "SCREEN_COUNT";
  
      private String dialogTitle = null;
      private String textPrompt = null;
      private String positiveButtonText = null;
      private int screenCount;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (savedInstanceState == null) {
              screenCount = 1;
              dialogTitle = "First Screen";
              textPrompt = "Click continue";
              positiveButtonText = "Continue";
          } else {
              dialogTitle = savedInstanceState.getString(DIALOG_TITLE);
              textPrompt = savedInstanceState.getString(TEXT_PROMPT);
              positiveButtonText = savedInstanceState.getString(POSITIVE_BUTTON_TEXT);
              screenCount = savedInstanceState.getInt(SCREEN_COUNT);
          }
      }
  
      @Override
      public void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          outState.putString(DIALOG_TITLE, dialogTitle);
          outState.putString(TEXT_PROMPT, textPrompt);
          outState.putString(POSITIVE_BUTTON_TEXT, positiveButtonText);
          outState.putInt(SCREEN_COUNT, screenCount);
      }
  
      @Override
      @NonNull
      public Dialog onCreateDialog(Bundle savedInstanceState) {
  
          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  
          LayoutInflater inflater = getActivity().getLayoutInflater();
          @SuppressLint("InflateParams")
          final View view = inflater.inflate(R.layout.dialog, null);
          builder.setView(view);
          builder.setTitle(dialogTitle);
          builder.setMessage(textPrompt);
          builder.setPositiveButton(positiveButtonText, null);
          builder.setNegativeButton("Cancel", null);
  
          AlertDialog dialog = builder.create();
  
          dialog.setOnShowListener(new DialogInterface.OnShowListener() {
  
              @Override
              public void onShow(final DialogInterface dialog) {
                  final AlertDialog alertDialog = (AlertDialog) dialog;
  
                  final Button okButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
                  okButton.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
  
                          if (screenCount == 3) {
                              dismiss();
                          } else {
                              screenCount++;
  
                              dialogTitle = "Screen Number " + screenCount;
                              alertDialog.setTitle(dialogTitle);
  
                              if (screenCount == 3) {
                                  // "OKOKOKOKO" won't cause the dialog title text to shrink!
                                  positiveButtonText = "OKOKOKOK";
                                  okButton.setText(positiveButtonText);
                              }
                          }
                      }
                  });
              }
          });
  
          return dialog;
      }
  }
  </code></pre>
  
  <p>And here are the screen shots of the 3 screens (the last 2 are cropped):</p>
  
  <p><a href="https://i.stack.imgur.com/4NWqU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4NWqU.png" alt="screen 1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/zAFeM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zAFeM.png" alt="screen 2 (cropped)"></a></p>
  
  <p><a href="https://i.stack.imgur.com/uA1XP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uA1XP.png" alt="screen 3 (cropped)"></a></p>
  
  <p>I notice the dialog shrunk slightly in width on the final screen, presumably because the layout is set to wrap its contents and the text on the positive button is shorter. So maybe the title text size is being shrunk automatically by Android as well to ensure it will still fit. But that's a guess.</p>
  
  <p>Does anyone know how to update the title text but keep it the same size throughout all the screens?</p>
  
  <p>I find it unintuitive that the the title text size changes at all. Can anyone explain why it does change size? Is this intended behaviour or an Android bug?</p>
  
  <p>The best solution won't involve setting the text size explicitly because then, if I ever change the app theme later on, I'll have to remember to change the title text size to match the theme in all of the multi-screen dialogs like this one.</p>