开发者

how to change the background image of Alertdialog

开发者 https://www.devze.com 2023-04-02 04:19 出处:网络
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

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)));
sta开发者_如何学Crt_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);

how to change the background image of Alertdialog


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消