android_agentWeb的使用

gradle:

compile 'com.just.agentweb:agentweb:4.0.2' // (必选)
compile 'com.just.agentweb:download:4.0.2' // (可选)
compile 'com.just.agentweb:filechooser:4.0.2'// (可选)

agentWeb加载网页

效果图:

点击agentWeb按钮跳转到工能练习页面

 layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_share"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.iamchan.fragmenttest.ui.ShareActivity">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include layout="@layout/layout_topbar"></include>
        <LinearLayout
            android:layout_weight="1"
            android:id="@+id/lin_web"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp">
        </LinearLayout>
    </LinearLayout>
<!--
 android:fadingEdge="none"
 android:overScrollMode="never"
-->
</RelativeLayout>

java:

private AgentWeb agentWeb;
private LinearLayout linWeb;
linWeb= (LinearLayout) findViewById(R.id.lin_web);

/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().setNavigationBarColor(Color.TRANSPARENT);
}*/



agentWeb=AgentWeb.with(this)
        .setAgentWebParent(linWeb, new LinearLayout.LayoutParams(-1, -1))
        .useDefaultIndicator()//进度条
        .createAgentWeb()
        .ready()
        .go("https://blog.csdn.net/iamchan/article/details/78743074");

重写的方法

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (agentWeb.handleKeyEvent(keyCode, event)) {
        return true;
    }
    return super.onKeyDown(keyCode, event);
}


@Override
protected void onPause() {
    agentWeb.getWebLifeCycle().onPause();
    super.onPause();

}

@Override
protected void onResume() {
    agentWeb.getWebLifeCycle().onResume();
    super.onResume();
}

@Override
protected void onDestroy() {
    agentWeb.getWebLifeCycle().onDestroy();
    super.onDestroy();
}

猜你喜欢

转载自blog.csdn.net/iamchan/article/details/83344453