how to change the background image of Alertdialog

2019-07-21 07:17发布

问题:

I have created an AlertDialog.Here i am able to change the backgroundImage of AlertDialog button. Now is it possible to chnage the background image of area at the back of button..I have send u the screen shot..so that it will make clear to you what i want..and the code i have used is..

        AlertDialog.Builder start_dialog = new AlertDialog.Builder(this);

        TextView start_dialog_title = new TextView(this);
        start_dialog_title.setText(m_res.getString(R.string.strt_dialog_title));
        start_dialog_title.setBackgroundResource(R.drawable.strt_dlg_tlt_bckgrnd);
        start_dialog_title.setGravity(Gravity.CENTER);
        start_dialog_title.setTextColor(Color.WHITE);
        start_dialog_title.setTextSize(20);         

        TextView start_dialog_desc = new TextView(this);
        start_dialog_desc.setText(Html.fromHtml(m_res.getString(R.string.strt_dialog_desc)));
        start_dialog_desc.setPadding(10, 10, 10, 10);
        start_dialog_desc.setBackgroundResource(R.drawable.strt_dlg_desc_bckgrnd);
        start_dialog_desc.setGravity(Gravity.CENTER);
        start_dialog_desc.setTextColor(Color.WHITE);
        start_dialog_desc.setTextSize(15);

        start_dialog.setCustomTitle(start_dialog_title);
        start_dialog.setView(start_dialog_desc);

        start_dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener()
        {                                   
            public void onClick(DialogInterface dialog, int id)
            {
                dialog.cancel();
            }
        });

        AlertDialog alert = start_dialog.create();
        alert.show();
        ((Button)alert.findViewById(android.R.id.button1)).setBackgroundResource(R.drawable.settings_but);

回答1:

Do not set the positive button. Have your own button in the layout file. That should solve your issue.



回答2:

yes you can but you must define youself button ,i suggest that you define whole alertdialog in xml and use it.