android - 如何更改 Alertdialog 的背景图像

标签 android background-image android-alertdialog

我创建了一个 AlertDialog。在这里我可以更改 AlertDialog 按钮的背景图像。现在可以更改按钮后面区域的背景图像吗?我已经把截图发给你了。这样你就会清楚我想要什么。这是我的代码:

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

最佳答案

不要设置正按钮。在布局文件中有自己的按钮。那应该可以解决您的问题。

关于android - 如何更改 Alertdialog 的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7281963/

相关文章:

CSS3 - 带有背景图像的交叉淡入淡出图像

css - CSS 中指定的背景图像不会出现在 iPad 中

android - 如何使用对话框 fragment ? (不推荐使用 showDialog)Android

android - 如果通过单击按钮 editText 为空,如何 toast 消息?

android - 解析.com : Sending a localized push notification to Android client - what does the client implementation look like?

android - bufferedReader() 在 Kotlin 中究竟是如何工作的?

android - map Intent 不显示指定位置

html - 带有CSS背景图像的div上的透明png

java - 在 android studio 中按键盘上的 Enter 键提交包含 EditText 的 AlertDialog.Builder

android - 复制网站以供离线使用