Android 6.0 Dialog text doesn't appear

后端 未结 11 2085
感情败类
感情败类 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:06

    Just put this in your styles file inside your Base Theme style tag and you are good to go

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

    I suspect that you are ending up showing white text on a white background! (Looking at the screenshot, the (i) icon is not showing up well either, suggesting that it was designed to be shown on a background other than white.

    You can use the constructor public AlertDialog.Builder (Context context, int themeResId) to ensure you are using a specific theme to style your dialog, where the Theme_Material_Dialog is probably what you want.

    0 讨论(0)
  • 2020-12-15 17:10
    new AlertDialog.Builder(context)
        .setTitle("Delete entry")
        .setMessage("Are you sure you want to delete this entry?")
        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                // continue with delete
            }
         })
        .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                // do nothing
            }
         })
        .setIcon(android.R.drawable.ic_dialog_alert)
         .show();
    

    Hope this will help you.............

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

    In my case all dialogs had the same color as fonts (title & message). What I have done to fix this state was the change of the color attribute in my theme. I copied the xml theme file into the 'res/values-v22' and set different color for marshmallow.

    <resources>
        <style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
            <item name="android:textColorPrimary">@android:color/tertiary_text_dark</item>
        </style>
    </resources>
    

    or only for dialogs

    <resources>
        <style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
            <item name="android:alertDialogTheme">@style/LywAlertDialogStyle</item>
        </style>
        <style name="LywAlertDialogStyle" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
            <item name="android:textColorPrimary">@color/lyw_secondary_text_color</item>
        </style>
    </resources>
    
    0 讨论(0)
  • 2020-12-15 17:16

    Use constructor with theme for Lollipop and newer android versions:

    Dark theme

        AlertDialog.Builder builder;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
        } else {
            builder = new AlertDialog.Builder(context);
        }
    

    And for Light theme

        AlertDialog.Builder builder;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert);
        } else {
            builder = new AlertDialog.Builder(context);
        }
    
    0 讨论(0)
  • 2020-12-15 17:16

    Maybe your main text color is the same as dialog background color, in that case in your styles.xml use (just an example):

    <style name="AlertDialog" parent="@android:style/Theme.Material.Light.Dialog.Alert">
        <item name="android:textColor">#000000</item>
    </style>
    

    and in dialog creation:

    new AlertDialog.Builder(
            new ContextThemeWrapper(getContext(), R.style.AlertDialog))
    ).setMessage("test");
    
    0 讨论(0)
提交回复
热议问题