當前位置:首頁 » 安卓系統 » android對話框進度條

android對話框進度條

發布時間: 2022-06-11 15:55:36

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 如何實現彈出一個進度條後,再彈出一個倒計時的界面。

實現流程

  1. Step One 彈出進度條對話框

  2. Step Two 執行線程,在線程中實現數據的非同步載入

  3. Step Three 在線程數據載入完成後,調用Handler並集合數據,更新界面

  4. 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

熱點內容
javafor循環嵌套if 發布:2025-08-18 23:28:21 瀏覽:297
西裝配領演算法 發布:2025-08-18 23:26:38 瀏覽:499
ecshopsql漏洞 發布:2025-08-18 23:17:01 瀏覽:798
mac臨時文件夾 發布:2025-08-18 23:14:55 瀏覽:765
阿里雲搭建傳奇伺服器 發布:2025-08-18 23:14:06 瀏覽:453
硬體加密卡 發布:2025-08-18 23:08:17 瀏覽:987
農信交易密碼指的是什麼密碼 發布:2025-08-18 23:03:20 瀏覽:585
數組存儲空間 發布:2025-08-18 23:01:50 瀏覽:748
如解壓游戲 發布:2025-08-18 22:57:02 瀏覽:576
如何復制頁游密碼 發布:2025-08-18 22:49:13 瀏覽:386