除了“对话框”进度条,也可以创建一个显示“操作进度”的对话框,例如显示正在下载的状态。
1. 创建一个工程:Dialog。
2. main.xml中的代码。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btn_dialog3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="onClick3" android:text="Click to display a detailed progress dialog" /> </LinearLayout>
3. DialogActivity.java中的代码。
public class DialogActivity extends Activity { ProgressDialog progressDialog; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onClick3(View v) { showDialog(1); progressDialog.setProgress(0); new Thread(new Runnable() { public void run() { for (int i = 1; i <= 15; i++) { try { // ---simulate doing something lengthy--- Thread.sleep(1000); // ---update the dialog--- progressDialog.incrementProgressBy((int) (100 / 15)); } catch (InterruptedException e) { e.printStackTrace(); } } progressDialog.dismiss(); } }).start(); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case 1: progressDialog = new ProgressDialog(this); progressDialog.setIcon(R.drawable.ic_launcher); progressDialog.setTitle("Downloading files..."); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show(); } }); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Toast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_SHORT).show(); } }); return progressDialog; } return null; } }
4. 按F11调试。
开发入门(一)详解活动 1.6 显示复杂对话框-复杂网络入门">
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索对话框
, public
, 进度
, savedinstancestate
, progressdialog
, OnCreate
, progressdialog进度条
, 进度条详解
, progressdialog用法
ProgressDialog进度框
复杂网络入门、时间复杂度详解、adams入门详解与实例、ping命令命令入门详解、redis快速入门详解ppt,以便于您获取更多的相关知识。