Search code examples
androidbackground-imageandroid-alertdialog

how to change the background image of Alertdialog


I have created an AlertDialog. Here I am able to change the backgroundImage of AlertDialog button. Now is it possible to change the background image of the area at the back of the button? I have sent you the screenshot. So that it will make clear to you what I want. Here is my code:

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);

enter image description here


Solution

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