How to change theme for AlertDialog

前端 未结 15 2162
名媛妹妹
名媛妹妹 2020-11-22 09:14

I was wondering if someone could help me out. I am trying to create a custom AlertDialog. In order to do this, I added the following line of code in styles.xml



        
15条回答
  •  一向
    一向 (楼主)
    2020-11-22 09:27

    Anyone trying to do this within a Fragment (using the support library i.e. pre API 11) should go with this:

    public class LoadingDialogFragment extends DialogFragment {
        public static final String ID = "loadingDialog";
    
        public static LoadingDialogFragment newInstance() {
            LoadingDialogFragment f = new LoadingDialogFragment();
    
            return f;
        }
    
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            StyleAlertDialog adb = new StyleAlertDialog(getActivity(), R.style.Your_Style);
            adb.setView(getActivity().getLayoutInflater().inflate(R.layout.fragment_dialog_layout, null));
            return adb;
        }
    
        private class StyleAlertDialog extends AlertDialog {
            protected StyleAlertDialog(Context context, int theme) {
                super(context, theme);
            }
        }
    }
    

    @Rflexor gave me the nudge to extend AlertDialog and expose the constructor thanks

提交回复
热议问题