Android AlertDialog does not display Message

dialog does not display message? ?

I encountered a very annoying problem when I wrote something recently. A simple Dialog, just a few words, can’t be displayed normally.,, I read the code back and forth several times, it’s no problem, it’s like the following So annoying! !

Write picture description here

Where did my message go? ? ?

I haven't tried it for a long time, and then I created a new project and wrote a dialog display, no problem? ? What's the situation? . . . .

Later, I searched a lot on the Internet. Many of them suggested to customize the contentView of the dialog, but I just displayed a text. It was too annoying every time, and I still want to know why it is not displayed.

Continue to search, find that it is replaced by AlertDialog in the support.v7 package, and I looked at my code, which is in the v7 package.

Finally, I finally found it, that is! ! Add a Style when new Builder! ! ! !

It should be that the AlertDialog in the V7 package needs to define its style, and the android.app.AlertDialog can be displayed normally without requiring it , and finally the problem is solved. .

Write picture description here

Oops, I blame myself for not mastering it well, so I should record it here for my own reference or other coders to laugh at. .


AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.Theme_AppCompat_Light_Dialog_Alert);
            builder.setMessage(R.string.upload_private_photo);
            builder.setPositiveButton(R.string.upload_public_photo, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

            });
            builder.create().show();

github address:

https://github.com/lizebinbin

Guess you like

Origin blog.csdn.net/lizebin_bin/article/details/78717756