Trying to change the appearance of the AlertDialog, I subclassed DialogFragment
with ThemedDialogFragment
and I called this lines onStart()
:
int alertTitleId = getResources().getIdentifier("alertTitle", "id", "android");
TextView alertTitle = (TextView) dialog.findViewById(alertTitleId);
alertTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen._20ssp));
That resulted in a NullPointerException
, even though I am sure there is a view with id alertTitle
in the window. The HierarchyViewer(*) tool confirms.
Tried to do minor variants
e.g.
int alertTitleId = getResources().getIdentifier("android:id/alertTitle", null, null);
or
TextView alertTitle = (TextView) dialog.getWindow().findViewById(alertTitleId);
or
TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
but none of this works.
Any idea, guys?
(*): HierarchyViewer shows the id I'm looking for exists
P.S.: I solved the AlertDialog
styling problem, by operating on the themes.xml
, I just want to know why this method didn't work (it should IMO).
Having said so, I will downvote every answer that tells me how to style an AlertDialog because it's off-topic here. Thanks.
P.P.S: As a sidenote, I tried this method compiling agains the sdk level 22 and tested it on an Android emulator running Android Jelly Bean 4.3.1.
P.P.P.S: No luck on an emulator running 5.1.1 either.