Andriod using WebView controls to embed pages in the app

Source: Internet
Author: User

1. Layout file fragment: Res-layout

<android:id= "@+id/toweb"       android:layout_width= "Fill_parent "       android:layout_height=" fill_parent "/>

2.Java Fragment: src

@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); //WebViewWebView browser=(WebView) Findviewbyid (R.id.toweb); Browser.loadurl ("Http://www.baidu.com"); //set to freely scale Web pagesBrowser.getsettings (). Setsupportzoom (true); Browser.getsettings (). Setbuiltinzoomcontrols (true); //If the page is linked, if you want to click on the link to continue responding in the current browser,//instead of the newly opened Android system browser should be linked, must overwrite WebView webviewclient objectBrowser.setwebviewclient (Newwebviewclient () { Public Booleanshouldoverrideurlloading (WebView view, String URL) {//Override this method to indicate that clicking on a link in the Web page or jumping in the current webview does not jump to the browser .view.loadurl (URL); return true;     }                      }); }          //Go back@Override Public BooleanOnKeyDown (intKeyCode, KeyEvent event) {WebView Browser=(WebView) Findviewbyid (R.id.toweb); //Check If the key event is the back button and if there's history        if((keycode = = Keyevent.keycode_back) &&Browser.cangoback ())              {Browser.goback (); return true; }        //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); }     

3. Androidmanifest.xml set permissions, otherwise cannot access

    <!-- Add this permission, WebView can access the Web page  -    <  android:name= "Android.permission.INTERNET"></  Uses-permission>       

Andriod using WebView controls to embed pages in the 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.