Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有消息的Android自定义进程对话框_Android_Progressdialog - Fatal编程技术网

带有消息的Android自定义进程对话框

带有消息的Android自定义进程对话框,android,progressdialog,Android,Progressdialog,我找到了很多关于如何在没有文本的情况下创建自定义ProgressDialog的教程。使用自定义图像和消息创建自定义ProgressDialog的最简单方法是什么。像这样的 创建自定义对话框 如果您想要自定义对话框设计,可以使用布局和小部件元素为对话框窗口创建自己的布局。定义布局后,将根视图对象或布局资源ID传递给setContentView(视图) 例如,要创建右侧显示的对话框,请执行以下操作: 创建另存为custom_dialog.XML的XML布局: <LinearLayout xml

我找到了很多关于如何在没有文本的情况下创建自定义ProgressDialog的教程。使用自定义图像和消息创建自定义ProgressDialog的最简单方法是什么。像这样的


创建自定义对话框

如果您想要自定义对话框设计,可以使用布局和小部件元素为对话框窗口创建自己的布局。定义布局后,将根视图对象或布局资源ID传递给setContentView(视图)

例如,要创建右侧显示的对话框,请执行以下操作:

创建另存为custom_dialog.XML的XML布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="10dp"
              >
    <ImageView android:id="@+id/image"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_marginRight="10dp"
               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              />
</LinearLayout>
实例化对话框后,使用setContentView(int)将自定义布局设置为对话框的内容视图,并向其传递布局资源ID。现在对话框已定义布局,您可以使用findViewById(int)从布局中捕获视图对象并修改其内容。 就这样。现在可以按照显示对话框中的说明显示对话框。 使用基本对话框类创建的对话框必须具有标题。如果不调用setTitle(),则用于标题的空间将保持为空,但仍然可见。如果您根本不需要标题,那么应该使用AlertDialog类创建自定义对话框。但是,由于AlertDialog是使用AlertDialog.Builder类最容易创建的,因此您无权访问上面使用的setContentView(int)方法。相反,您必须使用setView(视图)。此方法接受视图对象,因此需要从XML扩展布局的根视图对象

要展开XML布局,请使用GetLayoutFlater()(或getSystemService())检索LayoutFlater,然后调用inflate(int,ViewGroup),其中第一个参数是布局资源ID,第二个参数是根视图的ID。此时,您可以使用膨胀布局查找布局中的视图对象,并定义ImageView和TextView元素的内容。然后实例化AlertDialog.Builder并使用setView(视图)设置对话框的膨胀布局

以下是在AlertDialog中创建自定义布局的示例:

AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
                               (ViewGroup) findViewById(R.id.layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
通过将AlertDialog用于自定义布局,您可以利用内置的AlertDialog功能,如托管按钮、可选列表、标题、图标等


有关更多信息,请参阅Dialog和AlertDialog.Builder类的参考文档。

感谢您为我搜索它,我将坐在角落里几分钟以示惩罚。
AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
                               (ViewGroup) findViewById(R.id.layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();