android对话框进度条
A. Android ProgressBar amp;ProgressDialog 有什么区别
进度条,进度条对话框
ProgressDialog是继承自Android.app.ProgressDialog所设计的互动对话窗口,在应用时,必须新建ProgressDialog对象,在运行时会弹出“对话框”作为提醒,此时应用程序后台失去焦点,直到进程结束后,才会将控制权交给应用程序,如果在Activity当中不希望后台失焦,又希望提示User有某后台程序正处于忙碌阶段,此时就会使用ProgressBar了。
看你需求使用!!一般都是自定义
我觉得你用下这两个就知道了,自己多动手
B. android 进度条的值是怎么来的
①首先在XML进行布局
<progressBar
android:id="@+id/progressbar_updown"
android:layout_width="200dp"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:layout_gravity="center_vertical"
android:max="100"
android:progress="50"
android:secondaryProgress="70"
>
②代码中运用
private
ProgressBar
myProgressBar;
//定义ProgressBar
myProgressBar
=
(ProgressBar)
findViewById(R.id.progressbar_updown);
//ProgressBar通过ID来从XML中获取
myProgressBar.incrementProgressBy(5);
//ProgressBar进度值增加5
myProgressBar.incrementProgressBy(-5);
//ProgressBar进度值减少5
myProgressBar.incrementSecondaryProgressBy(5);
C. android中怎样消息提示框
在Android开发中,显示消息框有多种方法。
一、使用Toast显示提示信息框
Toast是一种非常方便的提示消息框,他会在程序界面上显示一个简单的提示信息,这个提示信息框用于向用户生成简单的提示信息,它具有两个特点。
1. Toast提示信息不会获得焦点,
2. Toast提示信息过一段时间会自动消失
使用Toast来生成提示消息也非常简单,只要如下几个步骤:
1. 调用Toast的构造器或makeText方法创建一个Toast对象。
2. 调用Toast的方法来设置该消息提示的对齐方式,页边距,显示内容等。
3. 调用Toast的show()方法,将他显示出来。
Toast的功能和用法都比较简单,大部分时候他只能显示简单的额文本提示如果应用需要显示诸如图片,列表之类的复杂提示,一般建议使用对话框完成,如果开发者确实想通过Toast来完成,也是可以的,Toast提供了一个setView()方法,该方法允许开发者自己定义Toast显示的内容。
下面贴一个例子代码:
package org.crazyit.toast;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class ToastTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button simple = (Button)findViewById(R.id.simple); //为按钮的单击事件绑定事件监听器
simple.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View source) {
//创建一个Toast提示信息
Toast toast = Toast.makeText(ToastTest.this,
"简单的提示信息"
// 设置该Toast提示信息的持续时间,
Toast.LENGTH_SHORT);
toast.show();
}
});
Button bn = (Button)findViewById(R.id.bn);
//为按钮的单击事件绑定事件监听器
bn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View source) {
//创建一个Toast提示信息
Toast toast = Toast.makeText(ToastTest.this,
"带图片的的提示信息"
// 设置该Toast提示信息的持续时间 ,
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
//获取Toast提示里原有的View
View toastView = toast.getView();
//创建一个ImageView
ImageView image = new ImageView(ToastTest.this);
image.setImageResource(R.drawable.tools);
//创建一个LinearLayout容器
LinearLayout ll = new LinearLayout(ToastTest.this);
//向LinearLayout中添加图片、原有的View
ll.addView(image);
ll.addView(toastView);
toast.setView(ll);
toast.show();
}
});
}
}
二、使用Builder对象
Builder dlg=new Builder(ServerInfoUpdate.this);
dlg.setTitle("Error");
dlg.setMessage("Unknown error.");
dlg.show();
三、使用AlertDialog对象
// 一个简单的弹出对话框
return new AlertDialog.Builder(this).setTitle("这是一个简单的弹出对话框的 Demo")
.create();
// 一个相对复杂的弹出对话框
return new AlertDialog.Builder(this)
.setTitle("标题") // 设置标题
// .setCustomTitle(View) // 以一个 View 作为标题
.setIcon(R.drawable.icon01) // 设置标题图片
// .setMessage("信息") // 需要显示的弹出内容
.setPositiveButton("确定", new OnClickListener() { // 设置弹框的确认按钮所显示的文本,以及单击按钮后的响应行为
@Override
public void onClick(DialogInterface a0, int a1) {
TextView txtMsg = (TextView) Main.this.findViewById(R.id.txtMsg);
txtMsg.append("单击了对话框上的“确认”按钮\n");
}
})
.setItems(R.array.ary, new DialogInterface.OnClickListener() { // 弹框所显示的内容来自一个数组。数组中的数据会一行一行地依次排列
public void onClick(DialogInterface dialog, int which) {
}
})
// 其他常用方法如下
// .setMultiChoiceItems(arg0, arg1, arg2)
// .setSingleChoiceItems(arg0, arg1, arg2)
// .setNeutralButton(arg0, arg1)
// .setNegativeButton(arg0, arg1)
.create();
四、弹出进度条对话框
ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("loading...");
return progress;
D. Android常用对话框有哪些
1、对话框通知(Dialog Notification)
当你的应用需要显示一个进度条或需要用户对信息进行确认时,可以使用对话框来完成。
2、创建带单选项列表的对话框
3、创建带多选项列表的对话框
4、进度对话框(ProgressDialog)
E. android进度条怎么显示百分比
显示百分比需要自己计算加载的内容,以下以webView示例,webView加载网页的时候可以增加进度条:
1.从webView中获取设置
WebSettings sws = webView.getSettings();
sws.setSupportZoom(true);
sws.setBuiltInZoomControls(true);
webView.setInitialScale(25);
webView.getSettings().setUseWideViewPort(true);
2.注册setWebChromeClient事件
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activity和Webview根据加载程度决定进度条的进度大小
// 当加载到100%的时候 进度条自动消失
//WebViewProgressActivity.this.setTitle("Loading...");
//WebViewProgressActivity.this.setProgress(progress * 100);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
//WebViewProgressActivity.this.setTitle("完成");
}
}
});
3.注意在onProgressChanged中处理进度,progress就是进度值。
F. 安卓怎么在在对话框中 搞一个进度条
方法/步骤:
单击按钮,弹出对话框,对话框中有进度条!
下面
来实现这个功能了
新建一个android工程,定义好xml
只需要一个button就可以了
在MainAtvity中,定义
ProgressDialog
m_pDialog;
创建单击响应事件
在OncliView中可以
m_pDialog
=
new
ProgressDialog(MainActivity.this);
//
设置进度条风格,风格为圆形,旋转的
m_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//
设置ProgressDialog
标题
m_pDialog.setTitle("提示");
//
设置ProgressDialog
提示信息
m_pDialog.setMessage("这是一个圆形进度条对话框");
//
设置ProgressDialog
标题图标
//
设置ProgressDialog
的进度条是否不明确
m_pDialog.setIndeterminate(false);
//
设置ProgressDialog
是否可以按退回按键取消
m_pDialog.setCancelable(true);
m_pDialog.show();
4
完成,单击按钮
就可以弹出对话框,(包含进度条~~)
G. android 如何实现弹出一个进度条后,再弹出一个倒计时的界面。
实现流程
Step One 弹出进度条对话框
Step Two 执行线程,在线程中实现数据的异步加载
Step Three 在线程数据加载完成后,调用Handler并集合数据,更新界面
Java代码
//添加异步操作
m_Dialog=ProgressDialog.show(m_context, "请等待...", "正在下载安装文件,请稍后...",true);
//mRegsiterHandler.sleep(100);
new Thread(new Runnable(){
@Override
public void run() {
//加载数据
result=0;
try{
//下载文件
String url="http://00.00.00.00:80/nationaltest.html";
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response;
response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();
InputStream is = entity.getContent();
FileOutputStream fileOutputStream = null;
if (is != null) {
File file = new File(Environment.getExternalStorageDirectory(), "nationaltest.apk");
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int ch = -1;
while ((ch = is.read(buf)) != -1) {
fileOutputStream.write(buf, 0, ch);
}
}
fileOutputStream.flush();
if (fileOutputStream != null) {
fileOutputStream.close();
}
result=2;
}
catch(Exception ex){
result=-1;
}
//更新界面
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
if(result==2)
install();
else
Toast.makeText(m_context, "下载文件失败,请检查网络连接", Toast.LENGTH_SHORT).show();
}
});
m_Dialog.dismiss();
}}).start();
}
H. android怎么使用自定义进度条对话框中的控件
在需要引用自定义进度条的xml的ProgressBar中添加android:indeterminateDrawable="@drawable/自定义进度条xml文件名称"
I. Android开发中,关于对话框中的圆形进度条和Layout的问题
首先解决问题一的问题:
你肯定使用了系统的 oncreateDialog 和 showdialog 方法了,所以 这个就会显示一次 第二次不显示了 , 你应该调用 dialog方法里面的 show()方法 来显示,这样每次显示那个progressbar都会在转圈
问题二:
你说下面设置了一个白色背景,但是下面还是有个框,不过我有个疑问,如果你设置为白色背景,那么你的转条默认是白色的不就看不见了吗?好了这个问题不纠结了!那个黑色的是边框导致的,去掉边框就行了
一般我们采用的是自定义dialog,也就是写一个类来继承dialog,这个时候的构造函数是这个:
public MyDialog(Context context, int theme) {
super(context, theme);
this.context = context;
init();
}
这个theme是什么东西呢? 就是一个style样式 如下:
<resources> <style name="dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item><!--边框-- <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上--
<item name="android:windowIsTranslucent">false</item><!--半透明-- <item name="android:windowNoTitle">true</item><!--无标题-- <item name="android:windowBackground">@color/transparent</item><!--背景透明-- <item name="android:backgroundDimEnabled">false</item><!--模糊-- </style></resources>
其他代码:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Dialog dialog = new MyDialog(this, R.style.MyDialog);
android.view.WindowManager.LayoutParams pa3 = new android.view.WindowManager.LayoutParams();
pa3.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
pa3.width = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
pa3.x = 0;//x 起点
pa3.y = 0;//y起点
Window window = dialog.getWindow();
window.setAttributes(pa3);
dialog.show();
return super.onKeyDown(keyCode, event);
}
之所以android.view.WindowManager.LayoutParams我要这么写,因为LayoutParams太多了,我害怕你找半天,兄弟对你够好了吧!
要是选为精彩回答 那就谢谢你了!
J. android 进度条,暂停,继续怎么弄
Handler和ProgressBar实现进度条的开始,暂停,停止,后退和循环
一,涉及的handler类方法
1,
post(Runnable r)
Causes the Runnable r to be added to the message queue.将要执行的线程对象加到队列当中
2,
removeCallbacks(Runnable r)
Remove any pending posts of Runnable r that are in the message queue.移除队列当中未执行的线程对象
3,
postDelayed(Runnable r, long delayMillis)
Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.
将要执行的线程对象放入到队列当中,待时间结束后,运行制定的线程对象
二,编写程序
程序效果:实现进度条的开始,暂停,停止,后退和循环
http://blog.csdn.net/superjunjin/article/details/7539844