Ich bin Anfänger in Android-Entwicklung, ich habe das Problem, dass ich weiße Seite bekomme, bevor meine webview lädt.So möchte ich diese weiße Seite entfernen, so dass nach dem platsch Bildschirm wird es Webview statt weiße Seite laden, bitte helfen Sie mir bei der Reparatur dieses.Erste weiße Seite Bevor mein Webview lädt in Android Webview App
Hier ist mein Mainactivity.java Source Code:
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import java.lang.reflect.Field;
@SuppressLint("SetJavaScriptEnabled")
@SuppressWarnings("ResourceAsColor")
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SwipeRefreshLayout swipeView =(SwipeRefreshLayout)findViewById(R.id.container);
ConnectivityManager cManager = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cManager.getActiveNetworkInfo();
//assign myWebView to webView
final WebView myWebView = (WebView) findViewById(R.id.webView);
//Load page URL
myWebView.loadUrl("https://mobile-tech2dsk.blogspot.in");
//Enable Javascript
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
//Link opens in the Webview
myWebView.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url) {
// do your stuff here
swipeView.setRefreshing(false);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
myWebView.loadUrl("file:///android_asset/error.html");
}
});
swipeView.setColorScheme(android.R.color.holo_blue_dark,android.R.color.holo_blue_light);
swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
{
@Override
public void onRefresh()
{
swipeView.setRefreshing(true);
(new Handler()).postDelayed(new Runnable()
{
@Override
public void run()
{
myWebView.loadUrl("javascript:window.location.reload(true)");
}
}, 2000);
}
});
}
//Adding go back button for page history
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
//assign myWebView to webView
WebView myWebView = (WebView) findViewById(R.id.webView);
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Hier ist mein Activity_Main.xml Code:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
plz help me zur Korrektur dieser –
Ihre Seite braucht Zeit, um die Seite zu laden, das ist, warum Sie die weiße Seite sehen. –
Wie kann ich Fortschrittsbalken hinzufügen \ –