zoukankan      html  css  js  c++  java
  • 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 七种进度条的样式,希望大家喜欢。

  • 相关阅读:
    [JLOI2013]地形生成[组合计数]
    [Luogu1891]疯狂LCM[辗转相减法]
    [BZOJ3745][COCI2015]Norma[分治]
    [BZOJ4028][HAOI2015]公约数数列[分块+分析暴力]
    [BZOJ4476][JSOI2015]送礼物[分数规划+单调队列]
    【JZOJ4893】【NOIP2016提高A组集训第15场11.14】过河
    【JZOJ4890】【NOIP2016提高A组集训第14场11.12】随机游走
    【JZOJ4889】【NOIP2016提高A组集训第14场11.12】最长公共回文子序列
    【JZOJ4888】【NOIP2016提高A组集训第14场11.12】最近公共祖先
    【JZOJ4887】【NOIP2016提高A组集训第13场11.11】最大匹配
  • 原文地址:https://www.cnblogs.com/CCCrunner/p/11781883.html
Copyright © 2011-2022 走看看