Android 6.0 Dialog text doesn't appear

后端 未结 11 2002
感情败类
感情败类 2020-12-15 17:02

I updated my phone to Android 6.0 and I have these 2 problems with dialogs:

1)The title is shown but the messages isn\'t for alert dialog(SOLVED):

          


        
相关标签:
11条回答
  • 2020-12-15 17:18
    @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the Builder class for convenient dialog construction
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(R.string.dialog_fire_missiles)
                   .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           // FIRE ZE MISSILES!
                       }
                   })
                   .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           // User cancelled the dialog
                       }
                   });
            // Create the AlertDialog object and return it
            return builder.create();
        }
    

    Once check this hope this will work.......

    0 讨论(0)
  • 2020-12-15 17:20

    When using DialogFragment you need to

    1. Add style

      <style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
          <item name="android:windowNoTitle">false</item>
      </style>
      
    2. In your DialogFragment add getTheme

      public class CustomDialogFragment extends DialogFragment{
          public int getTheme() { 
              return R.style.CustomDialogFragment; 
          }
          .
          .
          .
      

    And that's it!

    0 讨论(0)
  • 2020-12-15 17:23

    I've come across a few answers that say that you should use the following in your app theme:

    <item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
    

    While that is correct, it wasn't working in all places for me. Eventually, I realized that in some places I was using the regular AlertDialog builder and in other places I was using the support builder. If you are using the support AlertDialog, make sure to also include the following in your theme:

    <item name="alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
    
    0 讨论(0)
  • 2020-12-15 17:24

    i tried to fix this problem by making a style of my own.

    your dialog object should be like this and your style pointed to this Dialog will be written below

    new AlertDialog.Builder(new ContextThemeWrapper(Context, R.style.Dialog))
                .setTitle("Title")
                .setMessage("Sample Message ...").show();
    

    R.style.Dialog ::

    <style name="Dialog">
        <item name="android:textColorPrimary">@color/primary_text</item>
        <item name="android:textColor">@color/primary_color</item>
    </style>
    

    Colors ::

    <color name="primary_text">#212121</color>
    <color name="primary_color">#2196f3</color>
    

    finally the output should be something like this

    Note : "android:textColorPrimary" goes for dialog setMessage and "android:textColor" goes for dialog setTitle ; i do not use setPositive and setNegative button and listener in my dialog object but you can see them in the picture if you want you can make your own dialog object.

    0 讨论(0)
  • 2020-12-15 17:27

    Answer for 2), we need to call setStyle() before onCreateDialog() because theme is used in onCreateDialog()

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setStyle(STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog_Alert);
        }
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.setTitle(R.string.dialog_title);
        return dialog;
    }
    
    0 讨论(0)
提交回复
热议问题