Android webview normally displays frameset IFRAME in HTML

Source: Internet
Author: User

When webview opens HTML files with frameset tags, they are often not displayed completely. Only the last page is displayed.

You can simply set it.

Overwrite shouldoverrideurlloading and return false;

Mwebview. setwebviewclient (New webviewclient (){
@ Override
Public Boolean shouldoverrideurlloading (webview view, string URL ){

Return false; // false indicates frameset. True indicates no frameset.

}
}

The Code is as follows:

Package CN. HPC. cai. webview; import android. OS. bundle; import android. app. activity; import android. graphics. bitmap; import android. view. menu; import android. view. view; import android. webKit. webview; import android. webKit. webviewclient; import android. widget. toast; public class mainactivity extends activity {@ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcon Tentview (R. layout. activity_main); Init () ;}@ overridepublic Boolean oncreateoptionsmenu (menu) {// inflate the menu; this adds items to the action bar if it is present. getmenuinflater (). inflate (R. menu. activity_main, menu); Return true;} private webview mwebview; private void Init () {mwebview = (webview) findviewbyid (R. id. web_view); mwebview. setwebviewclient (New webviewclient () {@ override public boo Lean shouldoverrideurlloading (webview view, string URL) {toast. maketext (mainactivity. this, "shouldoverrideurlloading" + URL, toast. length_short ). show (); Return false; // false: Display frameset; true: Do not display frameset} @ override public void onpagestarted (webview view, string URL, bitmap favicon) {// callback when page Jump exists} @ override public void onpagefinished (webview view, string URL) {// callback after page Jump ends} @ override public v Oid onreceivederror (webview view, int errorcode, string description, string failingurl) {toast. maketext (mainactivity. This, "Oh no! "+ Description, toast. length_short ). show () ;}}); // string url = "<HTML> <frameset Cols = \" 25%, 25% \ "frameborder = No framespacing = 0 border = 0> <frame src = \" file: /// sdcard/demo.html "// +" \ "/> <frame src = \" file: /// sdcard/left.htm \ "/> </frameset> 

Layout file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MainActivity" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        android:text="@string/hello_world" />    <WebView        android:id="@+id/web_view"        android:layout_width="fill_parent"        android:layout_height="fill_parent" /></LinearLayout>

Related Article

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.