将背景图片应用于AlertDilog

4
我想以不同的样式显示菜单,因此我想给alertdialog设置背景图像。
有没有任何教程或链接可以帮助我实现我的目标?
1个回答

4

好的,您可以在自定义视图中创建AlertDialog,在该自定义视图中仅分配所需的背景。然后将该视图设置为AlertDialog自定义视图。 例如: - 一个RelativeCustomLayout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/shape_1"
    android:padding="10dip">
        ............
</RelativeLayout>

现在,将此视图展开并设置为对话框自定义视图

protected void createCustomDialog(int drawable, String title, String message){
        LayoutInflater inflater = LayoutInflater.from(WkActivity.this);
        View customDialog = inflater.inflate(R.layout.generic_error_dialog, null);
        ((TextView)customDialog.findViewById(R.id.genericErrorDialogTitle)).setText(title);
        ((TextView)customDialog.findViewById(R.id.genericErrorDialogMessage)).setText(message);
        ((ImageView)customDialog.findViewById(R.id.genericErrorDialogIcon)).setImageResource(drawable);

        dialog = new AlertDialog.Builder(WkActivity.this).create();
        dialog.setView(customDialog);
        dialog.setButton(getText(R.string.listaBusquedasGuardadasNoResultDialogButton), onClickListener);
        dialog.show();
    }

希望这能帮到你。

是的...谢谢您的回复,但我已经完成了它...它运行良好...再次感谢 - RobinHood

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接