1. add permissions: The permission "android. Permission. Internet" must be used in androidmanifest. xml. Otherwise, the web page not available error may occur. In androidmanifest. add <uses-Permission Android: Name = "android. permission. internet "/> </manifest> 2. Generate a webview component in the activity: webview = new webview (this); 3. Set Basic webview information: if the accessed page contains JavaScript, webview must be set to support JavaScript. Webview. getsettings (). setjavascriptenabled (true); the touch focus function requestfocus (); cancels the scroll bar this. setscrollbarstyle (scrollbars_outside_overlay); 4. Set the web page to be displayed for wevview: Internet use: webview. loadurl ("http://android.tgbus.com"); local file with: webview. loadurl (File: // android_asset/xx.html); local files in fixed formats are stored in: Assets files. 5. If you want to click a link, process it by yourself, instead of making a link in the browser of the new Android system. Add an event listening object (webviewclient) to webview and rewrite some of the methods shouldoverrideurlloading: Response to the hyperlink button in the webpage. When you press a connection, webviewclient will call this method and pass the parameter: the following URL onloadresource onpagestart onpagefinish onreceiveerror onreceivedhttpauthrequest 6. If you read many pages using the webview link, if you do not do any processing, click the system "back" key, the entire browser will call finish () to end itself. If you want to browse the Web page back rather than exit the browser, the back event needs to be processed and consumed in the current activity. Override the onkeydown (INT keycoder, keyevent event) method of the activity class. Public Boolean onkeydown (INT keycoder, keyevent event) {If (webview. cangoback () & keycoder = keyevent. keycode_back) {webview. goback (); // Goback () indicates that return true on the previous page of webview;} return false ;}
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.