Note that there are some explanatory texts on larger screens.

plurals
  1. POMy ProgressBar won't show while loading my WebView, why?
    primarykey
    data
    text
    <p>I have created a <code>WebViewActivity</code> extending <code>Activity</code> and showing a <code>WebView</code> inside of my app instead of redirecting to the browser.</p> <p>So I tried to use <code>AsyncTask</code> to show my <code>ProgressBar</code> while the view is loading. But the progress bar doesn't display at all. Here is the code I'm using:</p> <pre><code>import android.os.AsyncTask; import android.os.Bundle; import android.view.Window; import android.webkit.WebView; import android.widget.ProgressBar; import android.widget.TextView; import android.app.Activity; public class WebViewActivity extends Activity { WebView webView; TextView textView; ProgressBar bar; private class Async extends AsyncTask&lt;Void, Void, Void&gt; { protected Void doInBackground(Void... arg0) { return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); String url = new String(getIntent().getStringExtra("url")); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.loadUrl(url); textView.setText(getIntent().getStringExtra("title")); bar.setVisibility(ProgressBar.INVISIBLE); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_web_view); vueText = (TextView) findViewById(R.id.barTitle); vueWeb = (WebView) findViewById(R.id.WebView); bar = (ProgressBar) findViewById(R.id.progressBar); bar.setVisibility(ProgressBar.VISIBLE); new Async().execute(); } } </code></pre> <p>And here is my layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/grayBackground" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/barTitle" /&gt; &lt;ScrollView android:id="@+id/sc1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/barTitle" android:fillViewport="true" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;WebView android:id="@+id/WebView" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;ProgressBar android:id="@+id/progressBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:visibility="visible" /&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload