参考资料
dsbridge-android 的github的地址: https://github.com/wendux/DSBridge-Android
本项目android的源码:https://gitee.com/BenjaminSong/dsbridge-demo-android
编辑工具: Android Studio
vue端:https://www.jianshu.com/p/40716a69194d
1. 添加依赖。
打开 settings.gradle,在「dependencyResolutionManagement」的「repositories」中添加如下代码。
maven { url 'https://jitpack.io' }
image.png
打开 app/build.gradle ,在「dependencies」 中添加依赖。
此处添加的内容跟官方文档中有所出入
implementation 'com.github.wendux:DSBridge-Android:3.0.0'
// 腾讯X5内核,二选一,demo中选择的是上者。
implementation 'com.github.wendux:DSBridge-Android:x5-3.0.0'
打开 gradle.properties, 在其中添加
android.enableJetifier=true
image.png
2. 页面搭建。
编辑 res/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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">
<wendu.dsbridge.DWebView
android:id="@+id/mwebview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" />
</LinearLayout>
image.png
编辑 MainActivity.java,修改内容如下
public class MainActivity extends AppCompatActivity {
private DWebView dWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dWebView = findViewById(R.id.mwebview);
dWebView.setVerticalScrollBarEnabled(false);
dWebView.setHorizontalScrollBarEnabled(false);
dWebView.setWebContentsDebuggingEnabled(true);
dWebView.loadUrl("https://www.baidu.com/");
}
}
image.png
最终效果如下。
image.png
如上就代表dsbirdge引入成功了,只是最顶端Android的标题栏很影响页面,所以需要去除。
打开 res/values/themes.xml 文件,在resources标签下添加如下代码。
<style name="NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
image.png
再打开 AndroidManifest.xml,将其中的application标签中的 android:theme 改为 @style/NoActionBar
image.png
去除后的效果如下
image.png
如上代表接入成功!