8

Chrome や Reader のような Web ビューでプログレスバーを使用するアイデアはありますか? ここの一番下のように: ここに画像の説明を入力

4

1 に答える 1

0

これは、進行状況を表示するために使用したコードです。

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
WebView mWvUrl;

@Override
protected void onCreate(Bundle savedInstanceState) {
    final Activity activity=this;
    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    activity.setProgressBarIndeterminateVisibility(false);
     mWvUrl = (WebView) findViewById(R.id.wv_url);

     mWvUrl.getSettings().setJavaScriptEnabled(true);
     Button btnLoad = (Button) findViewById(R.id.btn_load);
     btnLoad.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
             EditText etUrl = (EditText) findViewById(R.id.et_url);
              mWvUrl.loadUrl(etUrl.getText().toString());
              activity.setProgressBarIndeterminateVisibility(true);
        }
    });

     mWvUrl.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                /** This prevents the loading of pages in system browser */
                return false;
            }

            /** Callback method, executed when the page is completely loaded */
            @Override
            public void onPageFinished(WebView view, String url) {
                 super.onPageFinished(view, url);

                 Toast.makeText(getBaseContext(),
                                "Page loaded Completely",
                                Toast.LENGTH_SHORT).show();

                /** Hiding Indeterminate Progress Bar in the title bar*/
                activity.setProgressBarIndeterminateVisibility(false);

            }

        });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}
于 2013-01-16T12:54:19.120 に答える