Missing buttons on AlertDialog | Android 7.0 (Nexus 5x)

前端 未结 9 1739
别那么骄傲
别那么骄傲 2020-12-05 13:19

I am trying to create an AlertDialog but the buttons are not showing. Only seeing this issue in Android 7.0:

final AlertDialog.Builder builder =         


        
相关标签:
9条回答
  • 2020-12-05 13:44

    So it turns out on Android 7.0 you have to provide a theme. At least, that's what I had to do.

        <style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <item name="borderlessButtonStyle">@style/Widget.AppCompat.Button.Borderless.Colored</item>
        </style>
    
    
        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
    
    0 讨论(0)
  • 2020-12-05 13:44

    Maybe its too late, but I hope someone would use this solution. you can do it something like this: You should set onShowListenter to your alertDialog, inside this function you should getButton() and than setTextColor to it. An example:

    alertDialog = alertDialogBuilder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener(){
        @Override
        public void onShow(DialogInterface dialogInterface){
            alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(R.color.black);
        }
    });
    
    0 讨论(0)
  • 2020-12-05 13:50

    I had a similar issue and the thing was that I wasn't using the support library for my AppCompatActivity, therefore I changed:

    import android.app.AlertDialog;
    

    to

    import android.support.v7.app.AlertDialog;
    

    and it worked.

    0 讨论(0)
提交回复
热议问题