简体   繁体   中英

How to avoid white screen in a webview when I press the back button on Android?

If I press the back button in my application, it shows a white screen. If I press it again, it shows my activity. How can I remove the white screen Activity?

This my Activity:

public class Facebook extends AppCompatActivity
{

   WebView fb_link;

   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_facebook);

       fb_link = (WebView) findViewById(R.id.fb);

       fb_link.getSettings().setJavaScriptEnabled(true);

       fb_link.loadUrl("https://www.facebook.com/profile.php id=100012806950302");

       fb_link.getSettings().setLoadsImagesAutomatically(true);

       fb_link.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

       fb_link.getSettings().getBuiltInZoomControls();

       fb_link.getSettings().setPluginState(WebSettings.PluginState.ON);

       fb_link.setInitialScale(1);

       fb_link.getSettings().setLoadWithOverviewMode(true);

       fb_link.getSettings().setUseWideViewPort(true);

       fb_link.setScrollbarFadingEnabled(false);

       fb_link.getSettings().setAllowFileAccess(true);

       fb_link.setWebChromeClient(new WebChromeClient());

   }

   public void onBackPressed()
   {

       if(fb_link!=null && fb_link.canGoBack())
           fb_link.goBack();// if there is previous page open it
       else
           super.onBackPressed();//if there is no previous page, close app
   }

}

我得到了答案...尝试在您的网络视图活动中显示清单android:onHistory =“ true”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM