安卓(Android) 怎么更改指定的进度条(ProgressBar)可见性或不确定的进度条

李逍遥
17352
文章
5
评论
2019年12月2日23:25:01 评论 1328字阅读4分25秒

1.简介

安卓(Android) 怎么更改指定的进度条(ProgressBar)可见性或不确定的进度条?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.View;
import android.widget.ProgressBar;

public class Main{

    public static void changeProgressBarVisibility(Activity activity,
            boolean show) {
        ProgressBar progressBar = (ProgressBar) activity
                .findViewById(android.R.id.progress);
        changeProgressBarVisibility(progressBar, activity, show);
    }

    public static void changeProgressBarVisibility(Fragment fragment,
            boolean show) {
        ProgressBar progressBar = (ProgressBar) fragment.getView()
                .findViewById(android.R.id.progress);
        changeProgressBarVisibility(progressBar, fragment.getActivity(),
                show);
    }

    public static void changeProgressBarVisibility(ProgressBar progressBar,
            Activity activity, boolean show) {
        if (progressBar != null) {
            if (show)
                progressBar.setVisibility(View.VISIBLE);
            else
                progressBar.setVisibility(View.GONE);
        } else {
            if (activity != null) {
                if (activity instanceof ActionBarActivity) {
                    ActionBarActivity actionBarActivity = (ActionBarActivity) activity;
                    actionBarActivity
                            .setSupportProgressBarIndeterminateVisibility(show);
                } else {
                    activity.setProgressBarIndeterminateVisibility(show);
                }
            }
        }
    }
}

 
展开全文
  • 版权声明: 发表于 2019年12月2日23:25:01
  • 转载注明:https://www.tah1986.com/44149.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: