crosswalk代替webview
生活随笔
收集整理的這篇文章主要介紹了
crosswalk代替webview
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
五步整合crosswalk內核瀏覽h5變高性能APP.
crosswalk介紹就不提了。我這里提供5個步驟整合到android項目中去。
開發環境: Android Studio
1.build.gradle Module配制
repositories {maven {url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'} }dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])compile 'org.xwalk:xwalk_core_library:23.53.589.4' }2.manifest.xml文件
需要注意:android:hardwareAccelerated="true" 為硬件加速
<!--需要權限--> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><applicationandroid:hardwareAccelerated="true"android:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/AppTheme" ><activity android:name=".MainActivity" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity> </application>3.布局文件
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.dowell.myapplication.MainActivity"><org.xwalk.core.XWalkViewandroid:id="@+id/xwalkWebView"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#000000"app:layout_constraintLeft_toLeftOf="parent"/></android.support.constraint.ConstraintLayout>4.java代碼
setContentView(R.layout.activity_main);xwalkWebView=(XWalkView)findViewById(R.id.xwalkWebView); xwalkWebView.load("http://www.baidu.com",null);XWalkSettings settings = xwalkWebView.getSettings(); settings.setDomStorageEnabled(true); settings.setCacheMode(WebSettings.LOAD_DEFAULT); settings.setAllowFileAccess(true); settings.setDatabaseEnabled(true); settings.setJavaScriptEnabled(true);//資源加載動作的事件 參考webview的setWebViewClient //xwalkWebView.setResourceClient(new XWalkResourceClient()); //界面相關的client 參照WebView setWebChromeClient //xwalkWebView.setUIClient(new MyXWalkUIClient(mXwalkView)); //js 交互相關,參照webview的addJavascriptInterface代碼 //xwalkWebView.addJavascriptInterface(new UMengInterface(), "UMeng"); 5.屏蔽crosswalk自動響應android返回鍵的事件。內置帶回退效果 @Override public boolean dispatchKeyEvent(KeyEvent event) {if(event.getKeyCode()==KeyEvent.KEYCODE_BACK){return true;}return super.dispatchKeyEvent(event); }參考:https://github.com/crosswalk-project/crosswalk-test-suite/blob/7b8527f7551548e7225700e78a11b82c371ae137/usecase/usecase-embedding-android-tests/embeddingapi/src/org/xwalk/embedded/api/sample/XWalkViewWithDispatchKeyEvent.java總結
以上是生活随笔為你收集整理的crosswalk代替webview的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在线网校平台搭建的流程
- 下一篇: ckfinder 配置 php,GitH