How to Use WebView seconds to make a simple browser app ?, Webviewapp

Source: Internet
Author: User

How to Use WebView seconds to make a simple browser app ?, Webviewapp

Here we will share with you a quick and easy-to-use browser app using the Webview component. The homepage is set to Baidu and you can define the display of the homepage according to your preferences.

We can see that three buttons are added below, respectively, corresponding to the back, back to the home page, not to mention the three features forward, now we provide code for everyone

First, create an xml file.

 
    
     
     
  
   
   
   
  
 

Then write in MainActivity. java

Package com. example. myapplication; import android. support. v7.app. appCompatActivity; import android. OS. bundle; import android. view. view; import android. webkit. webChromeClient; import android. webkit. webSettings; import android. webkit. webView; import android. webkit. webViewClient; import android. widget. button; public class webview extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_webview); final WebView webView = (WebView) findViewById (R. id. webview); webView. loadUrl (" https://www.baidu.com "); // You can select the website you need. // overwrite the webView by default, webView opens the web page through the system or a third-party browser. // webView can be opened if false to call the system or a third-party browser. setWebViewClient (new WebViewClient () {@ Override public boolean shouldOverrideUrlLoading (WebView view, String url) {// TODO Auto-generated method stub // webView loads the web resource view. loadUrl (url); return true ;}}); Button home = (Button) findViewById (R. id. home); Button go = (Button) findViewById (R. id. go); Button goback = (Button) findViewById (R. id. goback); home. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View view) {for (int I = 0; I <20; I ++) {webView. goBack () ;}}); go. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View view) {for (int I = 0; I <20; I ++) {webView. goForward () ;}}); goback. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View view) {webView. goBack ();}});}}

Finally, the most important thing is to require a network permission.

 

----------------------------------- After completing the preceding steps, you can implement a simple browser app ------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.