您的位置:首页 > 其它

ProgressDialog对话框

2015-09-21 20:47 176 查看
今天还讲了ProgressDialog对话框,就是显示进度条加载的对话框。

MainActivity:

package com.example.progressdialog;

import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener{

private Button btn1,btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) this.findViewById(R.id.btn1);
btn2 = (Button) this.findViewById(R.id.btn2);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn1:
ProgressDialog.show(MainActivity.this, "标题", "任务正在执行中,请稍候...",false,true);

break;
case R.id.btn2:
ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("标题");
dialog.setMessage("任务执行中,请稍候...");
dialog.setIndeterminate(false);
dialog.setCancelable(true);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.show();
break;
default:
break;
}
}

}
xml文件:

<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=".MainActivity" >
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="环形进度对话框"/>
<Button
android:id="@+id/btn2"
android:layout_below="@id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="水平进度对话框"/>
</RelativeLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: