Android 之 进度条样式

例1:(默认样式(中等圆形))

Xml代码

?
1
2
3
4
5
<ProgressBar
 android:id="@+id/progressBar1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />

例2:(超大圆形)

例1:(默认样式(中等圆形))

Xml代码

?
1
2
3
4
5
<ProgressBar
 android:id="@+id/progressBar1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />

例2:(超大圆形)

Xml代码

?
1
2
3
4
5
6
<ProgressBar
 android:id="@+id/progressBar2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 style="?android:attr/progressBarStyleLarge"
 />

例3:(小号圆形)

Xml代码

?
1
2
3
4
5
6
<ProgressBar
 android:id="@+id/progressBar3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 style="?android:attr/progressBarStyleSmall"
 />

例4:(标题小号圆形)

Xml代码

?
1
2
3
4
5
6
<ProgressBar
 android:id="@+id/progressBar4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 style="?android:attr/progressBarStyleSmallTitle"
 />

例4-在标题中使用小号圆形的使用代码:

 

Java代码

?
1
2
3
4
5
6
7
8
9
10
11
12
@Override
 
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 //设置标题不确定性进度条风格
 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
 setContentView(R.layout.progress_bars);
 //显示标题不确定性进度条
 setProgressBarIndeterminateVisibility(true);
 //关闭标题不确定性进度条
 //setProgressBarIndeterminateVisibility(false);
}

例5:(长方形进度条)

Xml代码

?
1
2
3
4
5
6
7
8
9
10
11
12
<ProgressBar
 android:id="@+id/progressBar5"
 android:layout_width="200dp"
 android:layout_height="wrap_content"
 style="?android:attr/progressBarStyleHorizontal"
 android:max="100"
 android:progress="50"
 android:secondaryProgress="70"
 />
   android:max="100" 最大进度值100
   android:progress="50" 当前初始化进度值50
   android:secondaryProgress="70" 当前初始化第2进度值70

例5-在标题中使用长方形进度条的代码:

 

Java代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 //设置标题进度条风格
 requestWindowFeature(Window.FEATURE_PROGRESS);
 setContentView(R.layout.progress_bars);
 //显示标题进度
 setProgressBarVisibility(true);
 //设置标题当前进度值为5000(标题进度最大值默认为10000)
 setProgress(5000);
 //关闭标题进度
 //setProgressBarVisibility(false);
}

例6:(进度对话框-圆形进度条)

 

Java代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ProgressDialog dialog = new ProgressDialog(this);
//设置进度条风格,风格为圆形,旋转的
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//设置ProgressDialog 标题
dialog.setTitle("进度对话框");
//设置ProgressDialog 提示信息
dialog.setMessage("圆形进度条");
//设置ProgressDialog 标题图标
dialog.setIcon(android.R.drawable.ic_dialog_map);
//设置ProgressDialog 的一个Button
dialog.setButton("确定", new ProgressDialog.OnClickListener(){
 @Override
 public void onClick(DialogInterface dialog, int which) {
 }
});
//设置ProgressDialog 的进度条是否不明确
dialog.setIndeterminate(false);
//设置ProgressDialog 是否可以按退回按键取消
dialog.setCancelable(true);
//显示
dialog.show();

例7:(进度对话框-长方形进度条)

 

Java代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ProgressDialog dialog = new ProgressDialog(this);
//设置进度条风格,风格为圆形,旋转的
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//设置ProgressDialog 标题
dialog.setTitle("进度对话框");
//设置ProgressDialog 提示信息
dialog.setMessage("长方形进度条");
//设置ProgressDialog 标题图标
dialog.setIcon(android.R.drawable.ic_dialog_alert);
//设置ProgressDialog的最大进度
dialog.setMax(100);
//设置ProgressDialog 的一个Button
dialog.setButton("确定", new ProgressDialog.OnClickListener(){
 @Override
 public void onClick(DialogInterface dialog, int which) {
 }
});
//设置ProgressDialog 是否可以按退回按键取消
dialog.setCancelable(true);
//显示
dialog.show();
//设置ProgressDialog的当前进度
dialog.setProgress(50);

通过本篇文章介绍了Android 七种进度条的样式,希望大家喜欢。

原文地址:https://www.cnblogs.com/CCCrunner/p/11781883.html