使用Android时,当我使用Web视图中的后退键时,会出现一个白色屏幕

我正在使用一个显示WebView的非常简单的活动,但是当我从Web视图返回到上一个活动时,会出现一个白色屏幕,并且我需要再次按下后退键才能成功。 有没有办法来防止这种情况?

Web活动Display_web.java:

public class Display_web extends Activity {
private WebView myWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String refOeuvre = intent.getStringExtra("REFOEUVRE");
    setContentView(R.layout.display_web);

    myWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setDomStorageEnabled(true);
    myWebView.loadUrl(refOeuvre);
}

@Override
public void onBackPressed() {
    if(myWebView!=null && myWebView.canGoBack())
        myWebView.goBack();// if there is previous page open it
    else
        super.onBackPressed();//if there is no previous page, close app
}

}

xml文件display_web.xml:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

我使用WebView和ListView调用新WebView的活动:

public class Display_alpha3 extends Activity {
public ListView mListOeuvres;
public WebView wikipediaCompo;

...... @Override保护无效onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState); 的setContentView(R.layout.display_alpha3); Intent intent = getIntent(); ...... mListOeuvres =(ListView)findViewById(R.id.list_oeuvres);

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(Display_alpha3.this,
            android.R.layout.simple_list_item_1, infoOeuvres);

    wikipediaCompo = (WebView) findViewById(R.id.wikipediaCompo);
    WebSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setDomStorageEnabled(true);
    wikipediaCompo.loadUrl(refCompo);
    wikipediaCompo.setWebViewClient(new WebViewClient()
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            return false;
        }
    });

    mListOeuvres.setAdapter(adapter);
    mListOeuvres.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String pos = String.valueOf(parent.getItemAtPosition(position));
            Intent i = new Intent(Display_alpha3.this, Display_web.class);
            i.putExtra("REFOEUVRE", refYouTube[position]);
            startActivity(i);
        }
    });
}

}

链接地址: http://www.djcxy.com/p/86065.html

上一篇: With Android, when i use the back key from a web view a white screen appears

下一篇: How to make an Android device vibrate?