【Android】对话框之进度条
2013-11-07 15:35
148 查看
1.最原始的进度条的实现:
这种只是单纯让用户等待而不显示任何信息。
2.下载进度条
3.自定义进度条
自定义一个类:
添加一个布局:
在Main中加入:
在定义类的时候可以不去继承Dialog,而是内部持有一个Dialog的引用。
这种只是单纯让用户等待而不显示任何信息。
button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //ProgressDialog.show(MainActivity.this, "提示", "正在加载请稍候...."); ProgressDialog dialog = new ProgressDialog(MainActivity.this); dialog.setTitle("提示"); dialog.setMessage("正在加载,请稍后。。。"); dialog.show(); //显示对话框 //dialog.dismiss(); //结合线程或者消息使用 } });
2.下载进度条
button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //第一种方式 //ProgressDialog dialog = new ProgressDialog(MainActivity.this,ProgressDialog.STYLE_HORIZONTAL); //第二种方式 ProgressDialog dialog = new ProgressDialog(MainActivity.this); dialog.setTitle("下载提示"); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setCancelable(false); //使它无法被取消 dialog.show(); dialog.setProgress(50);//放在show的后面,在线程中使用 } });
3.自定义进度条
自定义一个类:
package com.example.android_progress; 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 DialogSignin extends Dialog { private Context context; public DialogSignin(Context context) { // TODO Auto-generated constructor stub super(context); this.context = context; initDialog(); } public void initDialog(){ View view = LayoutInflater.from(context).inflate(R.layout.dialog_signin, null); //两种方式 //setContentView(view); setContentView(R.layout.dialog_signin); setTitle("自定义对话框"); TextView textView = (TextView)view.findViewById(R.id.username); textView.setText("zhangsan"); ImageView imageView = (ImageView)view.findViewById(R.id.image); imageView.setImageResource(R.drawable.ic_launcher); } }
添加一个布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="64dp" android:scaleType="center" android:background="#FFFFBB33" android:contentDescription="@string/app_name" /> <EditText android:id="@+id/username" android:inputType="textEmailAddress" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_marginBottom="4dp" android:hint="Username" /> <EditText android:id="@+id/password" android:inputType="textPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_marginBottom="16dp" android:fontFamily="sans-serif" android:hint="Password"/> </LinearLayout>
在Main中加入:
button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub DialogSignin dialog = new DialogSignin(MainActivity.this); dialog.show(); } });
在定义类的时候可以不去继承Dialog,而是内部持有一个Dialog的引用。
相关文章推荐
- Android 自定义对话框,进度条,下拉刷新等
- Android程序设计:显示后台任务进度对话框
- Android——简易进度条与对话框
- Android网络加载时显示进度条对话框
- Android动画之仿美团加载数据等待时,小人奔跑进度动画对话框(附顺丰快递员奔跑效果)
- Android ProgressDialog创建三种简单的进度对话框
- Android仿美团加载数据、小人奔跑进度动画对话框(附顺丰快递员奔跑效果)
- Android之ProgressBar ProgressDialog 进度条 进度条对话框
- Android中实现执行耗时操作时弹出进度对话框
- Android进阶UI之加载数据等待时,小人奔跑进度动画对话框
- Android开发之自定义圆角矩形进度对话框
- 安卓学习笔记---Android仿美团加载数据、小人奔跑进度动画对话框(以及顺丰快递员奔跑效果)
- 【Android】安卓UI 进度对话框ProgressDialog
- Android--水平进度条对话框
- android 进度对话框的使用
- Android:对话框(12种:警告对话框&进度条对话框&日期对话框&时间对话框)
- android源码分享,布局切换微信提醒对话框下拉刷新Cell进度动画代码下载
- Android开发之:在对话框中使用进度条
- Android的ProgressDialog进度对话框的使用
- Android -- 对话框 Dialog: 确定取消,单选多选,进度显示, 常用控件示例:单选多选框,下拉列表,进度条,自动完成文本框, 菜单显示