progressBar.setVisibility(View.GONE);有没有人告诉我停止加载后我可以在哪里使用 Progressbar

progressBar.setVisibility(View.GONE); Is there anybody please tell where i can use Progressbar gone after stop loading

我是 Java Android 开发的新手,我正在尝试开发一些东西,但我必须在 WebView 中使用进度条,但我不知道如何使用代码加载完成后停止进度条。

    private ProgressBar progressBar;

   mhelp = (LinearLayout) root.findViewById(R.id.lythelp);
                mhelp.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        progressBar.setVisibility(View.VISIBLE);
                        Intent intent = new Intent(getActivity(), Help.class);
                        startActivity(intent);
progressBar.setVisibility(View.GONE);


                    }
                });

开始新 activity 后不应设置进度条可见性。您可以做的最简单的事情是使用标志变量来保存进度条的状态。

startActivity(intent);
progressBar.setVisibility(View.GONE); // should be avoided

解决方案:

private ProgressBar progressBar;
String progressBarState = "empty"
String PROGRESS_BAR_LOADING = "LOADING"
String PROGRESS_BAR_LOADED = "LOADED"

mhelp = (LinearLayout) root.findViewById(R.id.lythelp);

mhelp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(PROGRESS_BAR_LOADING == "LOADING")
  progressBar.setVisibility(View.VISIBLE);

  Intent intent = new Intent(getActivity(), Help.class);
  startActivity(intent);
}

在 HelpActivity 中(或任何 activity 你想启动的):

override onCreate(): void {
  /*
  * You will need a progress bar on this activity's view 
  * as well if you are transitioning between activities and
  * want to maintain the progress.
  */

  progressBar.setVisibility(View.GONE);

  /*
  * You can pass the progress between the activities by
  * passing the completion rate through the bundle that is
  * sent through the activities.
  * You can also add a  key value pair for the progress bar's
  * current state in that bundle and check for that state in the
  * onCreate.
  */
}