• ProgressDialog 进度条的初步认识


    public class MainActivity extends Activity implements View.OnClickListener{
        private ProgressBar progress;
        private Button add;
        private Button reduce;
        private Button reset;
        private Button show;
        private TextView text;
        private ProgressDialog prodig;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            //注册控件
            init();
    
            add.setOnClickListener(this);
            reduce.setOnClickListener(this);
            reset.setOnClickListener(this);
            show.setOnClickListener(this);
        }
    
        private void init() {
            progress = (ProgressBar)findViewById(R.id.progressBar);
            add       = (Button) findViewById(R.id.button1);
            reduce   =  (Button) findViewById(R.id.button2);
            reset   =(Button)findViewById(R.id.button3);
            text    =(TextView)findViewById(R.id.textView);
            show    =(Button)findViewById(R.id.show);
    
    
            //获取进度
            int first =  progress.getProgress();
            int second=  progress.getSecondaryProgress();
            int Max   =  progress.getMax();
    
            text.setText("第一进度条百分比:" + ((int) (first / (float) Max * 100)) + "第二进度条百分比为:" + ((int) (second / (float) Max * 100)));
        }
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case  R.id.button1:
                    progress.incrementProgressBy(10);
                    progress.incrementSecondaryProgressBy(10);
                    break;
                case  R.id.button2:
                    progress.incrementProgressBy(-10);
                    progress.incrementSecondaryProgressBy(-10);
                    break;
                case  R.id.button3:
                    progress.setProgress(0);
                    progress.setSecondaryProgress(10);
                    break;
                case R.id.show:
                    //新建ProgressDialog对象
                    prodig = new ProgressDialog(MainActivity.this);
    
                    //设置ProgressDialog显示风格
                    prodig.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    
                    //设置ProgressDialog标题
                    prodig.setTitle("慕尼黑");
    
                    //设置ProgressDialog文本信息
                    prodig.setMessage("欢迎大家支持慕课网!");
    
                    //设置ProgressDialog图标
                    prodig.setIcon(R.mipmap.ic_launcher);
    
                    /*
                    设置ProgressBar进度条属性
                     */
                    //设定最大进度条
                    prodig.setMax(100);
    
                    //设定初始化进度
                    prodig.incrementProgressBy(50);
    
                    //进度条明确显示进度 设置为ture就会来回滚动 表示在运行
                    prodig.setIndeterminate(false);
    
                    /*
                    设定一个确定按钮
                     */
                    prodig.setButton(DialogInterface.BUTTON_POSITIVE,"确定可好?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity.this,"今天天气萌萌哒",Toast.LENGTH_SHORT).show();
                        }
                    });
    
                    //点击ProgressDialog区域来退出
                    prodig.setCancelable(true);
    
                    //显示ProgressDialog
                    prodig.show();
                    break;
            }
            text.setText("第一进度条百分比:" + ((int) (progress.getProgress() / (float) progress.getMax() * 100)) + "第二进度条百分比为:" + ((int) (progress.getSecondaryProgress() / (float) progress.getMax() * 100)));
        }
    

      注意:

    1.进度条明确显示进度 设置为ture就会来回滚动 表示在运行

    prodig.setIndeterminate(false);
    prodig.incrementProgressBy(50);


    2.ProgressDialog进度条 设置初始值时

    在show()之前 只能用

    prodig.incrementProgressBy(50);
    show()之后
    才能用prodig.setProgress(50);

    activity_main.xml
    <LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
        android:orientation="vertical"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
    
    
        <ProgressBar
            android:secondaryProgress="100"
            android:progress="50"
            android:max="100"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:progressDrawable="@drawable/asd"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/progressBar" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/plus"
            android:id="@+id/button1" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/minus"
            android:id="@+id/button2" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/reset"
            android:id="@+id/button3" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/show"
            android:id="@+id/show" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView" />
    
    </LinearLayout>
    

      

  • 相关阅读:
    go-micro registry 服务的注册和发现
    Element UI
    VUE常用插件和依赖的安装!
    Element dialog实现拖拽功能
    JAVA
    修改windows的host文件
    Vue
    Vue
    Vue
    Vue
  • 原文地址:https://www.cnblogs.com/zmaibbs7/p/4844142.html
Copyright © 2020-2023  润新知