AlertDialog: How To Remove Black Borders Above and Below View

后端 未结 5 1732
难免孤独
难免孤独 2020-12-05 06:47

This question has been asked before: AlertDialog custom title has black border

But was not answered satisfactorily - and is missing some information.


I

5条回答
  •  一个人的身影
    2020-12-05 07:22

    Just to make Steve's answer more clear, this can be done easily. For example in my case the view I was setting in the dialog was a WebView.

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    
        WebView webView = new WebView(getActivity());
        webView.loadUrl(" url to show ");
    
    
        OnClickListener clickListenerOk = new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ...
            }
        };
    
        OnClickListener clickListenerCancel = new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ...
            }
        };
    
        AlertDialog dialog = new AlertDialog.Builder(getActivity())
    
                .setPositiveButton("OK", clickListenerOk)
    
                .setNegativeButton("Cancel",clickListenerCancel)
    
                .create();
    
        dialog.setView(webView, 0, 0, 0, 0);
    
        return dialog;
    }
    

提交回复
热议问题