I found a way that only requires a one-line change to the Java code every time you create an AlertDialog.
Step 1
Create a custom, reusable layout containing a TextView with the correct font set. Name it alert_dialog.xml:
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" style="@style/SomeStyleWithDesiredFont" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/spacing_2x" />
Step 2
Create a reusable helper function somewhere that will inflate this layout and set the text to the desired line
public static TextView createMessageView(String message, Context context) { TextView messageView = (TextView) LayoutInflater.from(context).inflate(R.layout.alert_dialog, null, false); messageView.setText(message); return messageView; }
Step 3
In each AlertDialog.Builder chain in your code, replace this line:
.setMessage(messageString)
with this line:
.setView(createMessageView(messageString, context))
(Note that the same approach should work for a TextView header. You can use a custom view for the header by calling setCustomTitle () in your builder)
source share