Reputation: 199
i tried to use this solutions Android WebView progress bar
which gives me
final ProgressBar Pbar;
Pbar = (ProgressBar) findViewById(R.id.pB1);
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_browser);
browser=(WebView)findViewById(R.id.layout_browser);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setPluginsEnabled(true);
browser.getSettings().setPluginState(WebSettings.PluginState.ON);
browser.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
if(progress < 100 && Pbar.getVisibility() == ProgressBar.GONE){
Pbar.setVisibility(ProgressBar.VISIBLE);
}
Pbar.setProgress(progress);
if(progress == 100) {
Pbar.setVisibility(ProgressBar.GONE);
}
}
});
browser.loadUrl("google.com");
and adding a progress bar in my webview layout but it crashes, why ?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ProgressBar android:id="@+id/pB1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="2dip">
</ProgressBar>
<WebView android:id="@+id/layout_browser"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
Note : i will hide my status bar that's why I tried to use this method
Upvotes: 3
Views: 4198
Reputation: 109247
This line Pbar = (ProgressBar) findViewById(R.id.pB1);
should be after setContentView(R.layout.layout_browser);
Something like,
setContentView(R.layout.layout_browser);
Pbar = (ProgressBar) findViewById(R.id.pB1);
Upvotes: 2