如何申请背景图像AlertDilog图像、背景、AlertDilog

2023-09-05 08:25:27 作者:晚点遇见你

在我参加办法我想显示的菜单在不同的风格,我想给背景图片alertdialog。

In my appplication i want to display a menu in a different style for that I want give background image to alertdialog.

任何教程或链接,帮助我实现我的目标。

Any tutorial or link which help me to achieve my goal.

推荐答案

好了,你可以自定义视图中创建一个AlertDialog,在自定义视图只分配你想有一个背景。后来设置视图像AlertDialog自定义视图。 一个例子: - 一个RelativeCustomLayout:

well, you can create an AlertDialog within a custom view, in that custom view only assign a background you want. Later set that view like AlertDialog custom view. an example: - A 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>

现在,夸大这一观点,并设置类似对话框的自定义视图

now, inflate this view and set like dialog custom view

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

希望这有助于

hope this helps