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

2019年12月2日23:25:01安卓(Android) 怎么更改指定的进度条(ProgressBar)可见性或不确定的进度条已关闭评论 313 1330字阅读4分26秒

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);
                }
            }
        }
    }
}

 
继续阅读