I tried to get the message and the following line of code works:
TextView dialogMessage = (TextView)dialogObject.findViewById(android.R.id.message);
But when I try to get the title using the following line it returns null
TextView dialogTitle = (TextView)dialogObject.findViewById(android.R.id.tittle);
You can implement it your self. Create your own class that extend android.app.AlertDialog.Builder. And then create a variable to store your value after using the method setTitle().
And then use you can use it as ordinary AlertDialog, with implemented method which get its title. Then you can test it:
I know this is an old post but I used the accepted answer and added something else useful to me. You can make the Dialog title multiline (default 1 line) using the code below. I also read out the preset title because I added txt asynchronously later on using ContentLoaders
I know the question mentions AlertDialog, but if you came here through a Google search and looking for the answer for a
DialogFragment
:To avoid the code from breaking, when Google decides to change its dialog title view id in the future, here is more reliable solution.
We will simply return the first encountered
View
, which its type isTextView
.I checked up the code of the
AlertDialog
. Internally they useR.id.alertTitle
to initialize theAlertDialog
title'sTextView
. You can usegetIdentifier
to retrieve it: