Remove black background on custom dialog

前端 未结 13 2319
清歌不尽
清歌不尽 2021-01-30 20:54

I want to remove the black background on custom dialog as shown in the picture. I\'m sure the black background was from the dialog, not from app\'s background.

13条回答
  •  星月不相逢
    2021-01-30 21:20

    I had the same problem with my custom dialog based on the Alertdialog.Builder, which had a black background showing in the title and the body when i use:

    builder.setView(rootView)
      .setTitle(dialog_title)
      .setMessage(dialog_mesg)
    

    solution was 1- Use one of the pre-defines alert dialog builder's themes:

    • THEME_DEVICE_DEFAULT_DARK
    • THEME_DEVICE_DEFAULT_LIGHT
    • THEME_HOLO_DARK
    • THEME_HOLO_LIGHT THEME_TRADITIONAL

    THEME_DEVICE_DEFAULT_LIGHT worked best for me

    2 - set the default dialog button (positive / negative) colors to which ever color you desire like so:

     Button b = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
     Button d = mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
     b.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary));
     d.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary));
    

    check the below blog post for more detail and tricks to theming options: http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/

    tested on Oreo 8.1

提交回复
热议问题