Android对话框(二)进度条对话框ProgressDialog和自定义对话框CustomDialog
2015-01-26 20:32
489 查看
main.xml
![](https://img-blog.csdn.net/20150126203120375?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZG9uZ2xpYW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![](https://img-blog.csdn.net/20150126203202988?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZG9uZ2xpYW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![](https://img-blog.csdn.net/20150126203129562?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZG9uZ2xpYW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![](https://img-blog.csdn.net/20150126203211552?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZG9uZ2xpYW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
源代码下载
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.progressdialog.MainActivity" > <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="显示进度对话框一" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/button1" android:text="显示进度对话框二" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/button2" android:text="自定义对话框的使用" /> </RelativeLayout>custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout>
package com.example.progressdialog; import android.app.Dialog; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; public class CustomDialog { private Context context; Dialog dialog; public CustomDialog(Context context){ this.context = context; dialog = new Dialog(context); } public void show(){ View view = LayoutInflater.from(context).inflate(R.layout.custom_dialog, null); //inflate的第二个参数为null表示当前对话框的布局没根布局 dialog.setContentView(view); /* * setContentView(R.layout.custom_dialog); * 也可以以这种方式加载 */ dialog.setTitle("自定义的对话框"); ImageView imageView = (ImageView) view.findViewById(R.id.imageView1); imageView.setImageResource(R.drawable.ic_launcher); TextView textView = (TextView) view.findViewById(R.id.textView1); textView.setText("这是自定义对话框"); dialog.show(); } }
package com.example.progressdialog; import android.app.Activity; import android.app.ProgressDialog; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private Button button1; private Button button2; private Button button3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button3 = (Button) findViewById(R.id.button3); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { /* * ProgressDialog.show(MainActivity.this, "提示", "正在加载,请稍后..."); * 这样点击回退按钮没反应 */ ProgressDialog dialog = new ProgressDialog(MainActivity.this); dialog.setTitle("提示"); dialog.setMessage("正在加载,请稍后..."); dialog.show();//显示进度条,这样写点击回退按钮可退出进度对话框 } }); button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { /* * 第一个参数:上下文 * 第二个参数:主题样式 int theme * 第一种写法 * ProgressDialog dialog = new ProgressDialog(MainActivity.this, ProgressDialog.STYLE_HORIZONTAL); */ ProgressDialog dialog = new ProgressDialog(MainActivity.this); dialog.setTitle("下载提示"); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setProgress(50);//要显示进度,加线程 //dialog.setCancelable(false); dialog.show(); } }); button3.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub CustomDialog dialog = new CustomDialog(MainActivity.this); dialog.show(); } }); } }
源代码下载
相关文章推荐
- Android自定义对话框(Custom Dialog)
- Android 日常封装之暴力CustomViewDialog自定义对话框
- 【Android】高仿QQ对话框之自定义对话框CustomDialog
- 20. android dialog——自定义对话框之一
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android自定义对话框(Dialog)位置,大小
- android自定义Dialog实现文件下载和下载进度
- Android自定义Dialog(仿QQ同步助手退出对话框)
- android dialog——自定义对话框之一
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- [Android] Android自定义对话框(Dialog)位置,大小
- android Dialog 各种Dialog 三个选项的、进度条的、单选的、多选的、自定义的对话框
- android dialog ——ProgressDialog 进度条对话框详解
- Android Dialog( 自定义对话框)
- Android笔记:Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android对话框之ProgressDialog(进度对话框)
- android Dialog 各种Dialog 三个选项的、进度条的、单选的、多选的、自定义的对话框
- Android中自定义对话框(Dialog)
- Android AlertDialog 方法setView(view,0,0,0,0)开发自定义对话框