How to call findViewById in AlertDialog.Builder?

I am trying to get a link to TextViewin AlertDialogusing this code:

AlertDialog.Builder logoutBuilder = new AlertDialog.Builder(getActivity());      
TextView alertTextView = (TextView) logoutBuilder.findViewById(android.R.id.message);
alertTextView.setTextSize(40);

But I get a compiler error in findViewById:

Cannot cast from AlertDialog.Builder to Dialog
The method findViewById(int) is undefined for the type AlertDialog.Builder
+4
source share
1 answer

Create a dialog from AlertDialog.Builder, for example:

AlertDialog alert = builder.create();

Then from the warning you can call findViewById:

TextView alertTextView = (TextView) alert.findViewById(android.R.id.message);
alertTextView.setTextSize(40);
+11
source

All Articles