├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── libraries │ ├── animated_vector_drawable_23_4_0.xml │ ├── appcompat_v7_23_4_0.xml │ ├── hamcrest_core_1_3.xml │ ├── junit_4_12.xml │ ├── support_annotations_23_4_0.xml │ ├── support_v4_23_4_0.xml │ ├── support_vector_drawable_23_4_0.xml │ ├── tbs_sdk_v1_5_1_1057_25436_obfs_20160331_144900.xml │ └── xwalk_core_library_java.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── workspace.xml ├── LICENSE ├── README.md ├── WebViewDemo.iml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── libs │ └── tbs_sdk_v1.5.1.1057_25436_obfs_20160331_144900.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── android │ │ └── space │ │ └── lingen │ │ └── webviewdemo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── android │ │ │ └── space │ │ │ └── lingen │ │ │ └── webviewdemo │ │ │ └── Main │ │ │ ├── BaseFragmentActivity.java │ │ │ └── webview │ │ │ ├── MainActivity.java │ │ │ ├── activity │ │ │ ├── CrosswalkWebViewActivity.java │ │ │ ├── OrignalWebViewActivity.java │ │ │ └── X5WebViewActivity.java │ │ │ └── fragment │ │ │ ├── CrosswalkWebViewFragment.java │ │ │ ├── OrignalWebViewFragment.java │ │ │ └── X5WebViewFrament.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_navigation.xml │ │ ├── fragement_corsswalk_webview.xml │ │ ├── fragement_x5_webview.xml │ │ └── fragment_orignal_webview.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── home.png │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── android │ └── space │ └── lingen │ └── webviewdemo │ └── ExampleUnitTest.java ├── build.gradle ├── crosswalk ├── .gitignore ├── build.gradle ├── crosswalk.iml ├── libs │ └── xwalk_core_library_java.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── android │ │ └── space │ │ └── lingen │ │ └── crosswalk │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── jniLibs │ │ └── armeabi-v7a │ │ │ ├── libxwalkcore.so │ │ │ ├── libxwalkdummy.so │ │ │ └── native_lib_placeholder.stamp │ └── res │ │ ├── drawable-hdpi │ │ ├── bubble.9.png │ │ ├── bubble_arrow_up.png │ │ ├── color_picker_advanced_select_handle.png │ │ ├── dropdown_popup_background_down.9.png │ │ ├── dropdown_popup_background_up.9.png │ │ ├── ic_menu_share_holo_light.png │ │ ├── ic_search.png │ │ ├── ic_warning.png │ │ ├── ondemand_overlay.9.png │ │ └── verify_checkmark.png │ │ ├── drawable-v21 │ │ ├── button_borderless_compat.xml │ │ └── button_compat.xml │ │ ├── drawable-xhdpi │ │ ├── bubble.9.png │ │ ├── bubble_arrow_up.png │ │ ├── color_picker_advanced_select_handle.png │ │ ├── dropdown_popup_background_down.9.png │ │ ├── dropdown_popup_background_up.9.png │ │ ├── ic_menu_share_holo_light.png │ │ ├── ic_search.png │ │ ├── ic_warning.png │ │ ├── ondemand_overlay.9.png │ │ └── verify_checkmark.png │ │ ├── drawable-xxhdpi │ │ ├── ic_menu_share_holo_light.png │ │ ├── ic_search.png │ │ ├── ic_warning.png │ │ └── verify_checkmark.png │ │ ├── drawable-xxxhdpi │ │ ├── ic_menu_share_holo_light.png │ │ ├── ic_search.png │ │ ├── ic_warning.png │ │ └── verify_checkmark.png │ │ ├── drawable │ │ ├── autofill_chip_inset.xml │ │ ├── bubble.9.png │ │ ├── bubble_arrow_up.png │ │ ├── button_compat_shape.xml │ │ ├── color_button_background.xml │ │ ├── color_picker_advanced_select_handle.png │ │ ├── color_picker_border.xml │ │ ├── dropdown_label_color.xml │ │ ├── dropdown_popup_background.xml │ │ ├── dropdown_popup_background_down.9.png │ │ ├── dropdown_popup_background_up.9.png │ │ ├── ic_menu_share_holo_light.png │ │ ├── ic_search.png │ │ ├── ic_warning.png │ │ ├── ondemand_overlay.9.png │ │ └── verify_checkmark.png │ │ ├── layout-land │ │ └── date_time_picker_dialog.xml │ │ ├── layout-v17 │ │ ├── autofill_keyboard_accessory_item.xml │ │ ├── color_picker_advanced_component.xml │ │ ├── color_picker_dialog_content.xml │ │ ├── color_picker_dialog_title.xml │ │ ├── date_time_suggestion.xml │ │ ├── dropdown_item.xml │ │ ├── multi_field_time_picker_dialog.xml │ │ ├── two_field_date_picker.xml │ │ └── validation_message_bubble.xml │ │ ├── layout │ │ ├── autofill_keyboard_accessory_icon.xml │ │ ├── autofill_keyboard_accessory_item.xml │ │ ├── color_picker_advanced_component.xml │ │ ├── color_picker_dialog_content.xml │ │ ├── color_picker_dialog_title.xml │ │ ├── date_time_picker_dialog.xml │ │ ├── date_time_suggestion.xml │ │ ├── dropdown_item.xml │ │ ├── multi_field_time_picker_dialog.xml │ │ ├── two_field_date_picker.xml │ │ └── validation_message_bubble.xml │ │ ├── menu │ │ └── select_action_menu.xml │ │ ├── raw │ │ ├── contacts_api.js │ │ ├── device_capabilities_api.js │ │ ├── empty.wav │ │ ├── icudtl.dat │ │ ├── launch_screen_api.js │ │ ├── messaging_api.js │ │ ├── wifidirect_api.js │ │ └── xwalk.pak │ │ ├── values-am │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-ar │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-bg │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-ca │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-cs │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-da │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-de │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-el │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-en-rGB │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-es-rUS │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-es │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-fa │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-fi │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-fr │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-hi │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-hr │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-hu │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-in │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-it │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-iw │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-ja │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-ko │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-lt │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-lv │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-nb │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-nl │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-pl │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-pt-rBR │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-pt-rPT │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-ro │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-ru │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-sk │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-sl │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-sr │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-sv │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-sw │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-th │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-tl │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-tr │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-uk │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-v17 │ │ ├── styles.xml │ │ └── ui_java_styles.xml │ │ ├── values-v21 │ │ ├── styles.xml │ │ └── ui_java_styles.xml │ │ ├── values-vi │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-zh-rCN │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ ├── values-zh-rTW │ │ ├── android_content_strings.xml │ │ └── android_ui_strings.xml │ │ └── values │ │ ├── android_content_strings.xml │ │ ├── android_ui_strings.xml │ │ ├── android_xwalk_strings.xml │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ ├── styles.xml │ │ ├── ui_java_attrs.xml │ │ ├── ui_java_dimens.xml │ │ ├── ui_java_strings.xml │ │ ├── ui_java_styles.xml │ │ ├── values.xml │ │ ├── xwalk_app_strings.xml │ │ ├── xwalk_core_internal_java_strings.xml │ │ ├── xwalk_core_java_strings.xml │ │ └── xwalk_resources_list.xml │ └── test │ └── java │ └── android │ └── space │ └── lingen │ └── crosswalk │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample_webivew_android.iml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | sample_webivew_android -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/libraries/animated_vector_drawable_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/libraries/support_vector_drawable_23_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/tbs_sdk_v1_5_1_1057_25436_obfs_20160331_144900.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/xwalk_core_library_java.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Android WebView的几种选择对比 2 | 3 | 现在的移动开发,一个明显的趋势是HTML占据了越来越重要的位置,H5不再是简单的一个浏览网页的行为,在非常多的APP中,它承担了许多原本许要原生开发的功能;Android的H5支持则是个比较头痛的事情 4 | 5 | 6 | 7 | 笔者在进行IOS开发时,WebView从来都不是问题,在IOS上不仅WebView统一,而且性能极佳,也很少需要考虑兼容性问题; 8 | 9 | 但这个问题在Android上则表现的非常不一样,由于机型众多,WebView的内核众多,不同手机的WebView的兼容性,性能相差也比较大,如果你的APP在Android上对H5有较高需求,你就需要一个好的解决方案 10 | 11 | >笔者现在所在的公司所负责开发的APP,就是一款企业级APP,由于需要对接企业开发的各式各样的H5的业务系统,因此在H5方面要求较高;也因此笔者对这一方面了解稍等有一点 12 | 13 | Android WebView的选择有三种方案,分别是 14 | 15 | 1. 使用Android系统自带的WebView 16 | 2. 使用X5内核的WebView 17 | 3. 使用基于chrome webkit的crosswalk WebView 18 | 19 | 如上述三种方案,第1个是最原始的解决方案,第2,3个则分别是腾讯,corsswalk的解决方案 20 | 21 | 几种方案的对照如下表: 22 | 23 | | 方案 | 方案说明| 实际效果 | 优缺点 | html5test分数| 24 | |----------|---------|--------|-------|-------| 25 | | 系统自带WebView | Android默认 | 最差 | 优:没有额外的JAR及负担,原生API 缺: 兼容性,性能在不同手机上显示差别很大 | 最差 | 26 | | X5 WebView | 腾讯产品,微信,QQ浏览器就是使用X5内核 | 一般 | 优:提供了一个兼容性的解决方案,且微信,QQ浏览器都在用,可信度高 缺: 解决的能力一般,而且某些方面反而加大了开发工作量;而且不支持cordova | 一般| 27 | | crosswalk | 国外为Android提供的一个融合chrome webkit的解决方案 | 最佳 | 优:没有兼容性,性能问题,且支持corodva 缺:18M的包,而且区分不同的arm,x86等CPU | 较佳 28 | 29 | 笔者有一个较老的华为荣耀3C手机,购置于3年前,分别使用系统自带的WebView,X5 WebView,Crosswalk三种模式访问html5test网站,得出的评分结果分别是: 30 | 31 | > 系统自带的WebView 32 | ![自带WebView](http://media.lingenliu.com/android_webview_orignal.jpeg-default) 33 | 34 | > X5内核WebView 35 | ![X5内核](http://media.lingenliu.com/android_webview_x5.jpeg-default) 36 | 37 | > Crosswalk WebView 38 | ![crosswalk](http://media.lingenliu.com/android_webview_crosswalk.jpeg-default) 39 | 40 | 41 | 如上所述,crosswalk的效果是显而易见;笔者所有公司的APP项目也是使用crosswalk做为Android WebView 42 | 43 | 1. 使用Chrome Webkit内核,兼容性不存在任何问题 44 | 2. 性能佳 45 | 3. 支持cordova 46 | 4. 支持前端人员可以在PC Chrome上联调 47 | 48 | 不足: 49 | 50 | 1. APP包增加了至少18M 51 | 2. 不同的CPU系统的包完全不同,笔者APP只支持arm,如果你还要支持X86 CPU,你还得加18M的大小,或者分2个APP 52 | 53 | 54 | 而X5做为腾讯的一款产品,主要目标也是解决兼容性问题,从分数上看,它在H5的支持度上并没有太多的改善;但兼容性方面应该有比较好的改善,同时有微信和QQ浏览器做支撑,也是一个比较好的选择 55 | 56 | 因此,笔者最终建议如下: 57 | 58 | 1. 你的APP对WebView需求不高,以纯原生为主,那就不用考虑WebView的兼容性及性能问题,使用系统自带的WebView就可以了 59 | 2. 如果你的APP有大量使用到WebView,加载一些H5网页,但在cordova等其它方面有要求,使用X5是一个比较好的选择,毕竟腾讯的实力摆在那,有问题你可以说,微信也是这样的(这个话非常有杀伤力) 60 | 3. 类似笔者公司这样的APP,对H5有非常高的要求,大量的业务系统是由H5完成,且需要cordova与原生进行大量的交互 ,那这种情况下,crosswalk是我们唯一的选择,虽然加大了18M,但带来的好处是显而易见的 61 | 62 | -------------------------------------------------------------------------------- /WebViewDemo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "android.space.lingen.webviewdemo" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | 27 | compile project(':crosswalk') 28 | } 29 | -------------------------------------------------------------------------------- /app/libs/tbs_sdk_v1.5.1.1057_25436_obfs_20160331_144900.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lingen/sample_webivew_android/a7f03cfe639008bb4b51e019e4261bebfc15dd8b/app/libs/tbs_sdk_v1.5.1.1057_25436_obfs_20160331_144900.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/lingen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/android/space/lingen/webviewdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/BaseFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.space.lingen.webviewdemo.Main.webview.MainActivity; 6 | import android.space.lingen.webviewdemo.R; 7 | import android.support.annotation.Nullable; 8 | import android.support.v4.app.Fragment; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.view.View; 11 | import android.widget.ImageButton; 12 | 13 | /** 14 | * Created by lingen on 5/15/16. 15 | */ 16 | public abstract class BaseFragmentActivity extends AppCompatActivity{ 17 | 18 | 19 | private ImageButton homeButton; 20 | 21 | @Override 22 | protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | 26 | 27 | if (findViewById(R.id.fragment_common) != null){ 28 | if (savedInstanceState != null){ 29 | return; 30 | } 31 | 32 | Fragment fragment = getFragment(); 33 | getSupportFragmentManager().beginTransaction().add(R.id.fragment_common,fragment).commit(); 34 | 35 | this.homeButton = (ImageButton) findViewById(R.id.webview_home); 36 | 37 | 38 | this.homeButton.setOnClickListener(new View.OnClickListener() { 39 | @Override 40 | public void onClick(View v) { 41 | Intent intent = new Intent(); 42 | intent.setClass(getBaseContext(), MainActivity.class); 43 | 44 | startActivity(intent); 45 | } 46 | }); 47 | } 48 | 49 | } 50 | 51 | public abstract Fragment getFragment(); 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/webview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main.webview; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.space.lingen.webviewdemo.Main.webview.activity.CrosswalkWebViewActivity; 6 | import android.space.lingen.webviewdemo.Main.webview.activity.OrignalWebViewActivity; 7 | import android.space.lingen.webviewdemo.Main.webview.activity.X5WebViewActivity; 8 | import android.space.lingen.webviewdemo.R; 9 | import android.support.annotation.Nullable; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.ImageButton; 14 | 15 | import java.util.zip.CRC32; 16 | 17 | /** 18 | * Created by lingen on 5/15/16. 19 | */ 20 | public class MainActivity extends AppCompatActivity { 21 | 22 | 23 | //原生浏览器WEBVIEW 24 | private Button orignalWebViewButton; 25 | 26 | //X5内核WEBVIEW 27 | private Button x5WebViewButton; 28 | 29 | //crosswalk WebView 30 | private Button crosswalkButton; 31 | 32 | 33 | 34 | @Override 35 | protected void onCreate(@Nullable Bundle savedInstanceState) { 36 | 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_navigation); 39 | findView(); 40 | registerListener(); 41 | 42 | } 43 | 44 | 45 | private void findView(){ 46 | this.orignalWebViewButton = (Button) findViewById(R.id.button_original); 47 | 48 | this.x5WebViewButton = (Button) findViewById(R.id.button_x5); 49 | 50 | this.crosswalkButton = (Button) findViewById(R.id.button_crosswalk); 51 | 52 | 53 | } 54 | 55 | private void registerListener(){ 56 | this.orignalWebViewButton.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View v) { 59 | Intent intent = new Intent(); 60 | intent.setClass(getBaseContext(),OrignalWebViewActivity.class); 61 | MainActivity.this.startActivity(intent); 62 | } 63 | }); 64 | 65 | this.x5WebViewButton.setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View v) { 68 | Intent intent = new Intent(); 69 | intent.setClass(getBaseContext(),X5WebViewActivity.class); 70 | MainActivity.this.startActivity(intent); 71 | 72 | } 73 | }); 74 | 75 | this.crosswalkButton.setOnClickListener(new View.OnClickListener() { 76 | @Override 77 | public void onClick(View v) { 78 | Intent intent = new Intent(); 79 | intent.setClass(getBaseContext(),CrosswalkWebViewActivity.class); 80 | MainActivity.this.startActivity(intent); 81 | 82 | } 83 | }); 84 | 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/webview/activity/CrosswalkWebViewActivity.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main.webview.activity; 2 | 3 | import android.space.lingen.webviewdemo.Main.BaseFragmentActivity; 4 | import android.space.lingen.webviewdemo.Main.webview.fragment.CrosswalkWebViewFragment; 5 | import android.support.v4.app.Fragment; 6 | 7 | /** 8 | * Created by lingen on 5/15/16. 9 | */ 10 | public class CrosswalkWebViewActivity extends BaseFragmentActivity { 11 | @Override 12 | public Fragment getFragment() { 13 | return new CrosswalkWebViewFragment(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/webview/activity/OrignalWebViewActivity.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main.webview.activity; 2 | 3 | import android.space.lingen.webviewdemo.Main.BaseFragmentActivity; 4 | import android.space.lingen.webviewdemo.Main.webview.fragment.OrignalWebViewFragment; 5 | import android.support.v4.app.Fragment; 6 | 7 | /** 8 | * Created by lingen on 5/15/16. 9 | */ 10 | public class OrignalWebViewActivity extends BaseFragmentActivity { 11 | @Override 12 | public Fragment getFragment() { 13 | return new OrignalWebViewFragment(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/webview/activity/X5WebViewActivity.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main.webview.activity; 2 | 3 | import android.space.lingen.webviewdemo.Main.BaseFragmentActivity; 4 | import android.space.lingen.webviewdemo.Main.webview.fragment.X5WebViewFrament; 5 | import android.support.v4.app.Fragment; 6 | 7 | /** 8 | * Created by lingen on 5/15/16. 9 | */ 10 | public class X5WebViewActivity extends BaseFragmentActivity { 11 | @Override 12 | public Fragment getFragment() { 13 | return new X5WebViewFrament(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/webview/fragment/CrosswalkWebViewFragment.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main.webview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.space.lingen.webviewdemo.R; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import org.xwalk.core.XWalkView; 12 | 13 | /** 14 | * Created by lingen on 5/15/16. 15 | */ 16 | public class CrosswalkWebViewFragment extends Fragment { 17 | 18 | 19 | private XWalkView webView; 20 | @Nullable 21 | @Override 22 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 23 | View view = inflater.inflate(R.layout.fragement_corsswalk_webview,container,false); 24 | findView(view); 25 | return view; 26 | } 27 | 28 | private void findView(View view){ 29 | this.webView = (XWalkView) view.findViewById(R.id.webview_crosswalk); 30 | 31 | 32 | } 33 | 34 | @Override 35 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 36 | this.webView.load("http://html5test.com",null); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/webview/fragment/OrignalWebViewFragment.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main.webview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.space.lingen.webviewdemo.R; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.webkit.WebView; 11 | import android.webkit.WebViewClient; 12 | 13 | /** 14 | * Created by lingen on 5/15/16. 15 | */ 16 | public class OrignalWebViewFragment extends Fragment { 17 | 18 | private WebView webView; 19 | 20 | @Nullable 21 | @Override 22 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 23 | View view = inflater.inflate(R.layout.fragment_orignal_webview, container, false); 24 | findView(view); 25 | return view; 26 | } 27 | 28 | private void findView(View view){ 29 | this.webView = (WebView) view.findViewById(R.id.webview_original); 30 | 31 | this.webView.getSettings().setJavaScriptEnabled(true); 32 | this.webView.setWebViewClient(new WebViewClient(){ 33 | @Override 34 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 35 | webView.loadUrl(url); 36 | return true; 37 | } 38 | }); 39 | } 40 | 41 | @Override 42 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 43 | this.webView.loadUrl("http://html5test.com"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/android/space/lingen/webviewdemo/Main/webview/fragment/X5WebViewFrament.java: -------------------------------------------------------------------------------- 1 | package android.space.lingen.webviewdemo.Main.webview.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.space.lingen.webviewdemo.R; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.tencent.smtt.sdk.WebView; 12 | import com.tencent.smtt.sdk.WebViewClient; 13 | 14 | /** 15 | * Created by lingen on 5/15/16. 16 | */ 17 | public class X5WebViewFrament extends Fragment { 18 | 19 | private WebView webView; 20 | 21 | @Nullable 22 | @Override 23 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 24 | View view = inflater.inflate(R.layout.fragement_x5_webview,container,false); 25 | findView(view); 26 | return view; 27 | } 28 | 29 | private void findView(View view){ 30 | this.webView = (WebView) view.findViewById(R.id.webview_x5); 31 | this.webView.getSettings().setJavaScriptEnabled(true); 32 | this.webView.setWebViewClient(new WebViewClient(){ 33 | @Override 34 | public boolean shouldOverrideUrlLoading(WebView webView, String s) { 35 | webView.loadUrl(s); 36 | return true; 37 | } 38 | }); 39 | } 40 | 41 | @Override 42 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 43 | this.webView.loadUrl("http://html5test.com"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 |