Agentweb framework in the Java library
The Agentweb framework is a lightweight Web framework used in the Java library. It can easily embed it in the Android application to achieve loading and interaction of the web page.This article will introduce the use guidelines of the Agentweb framework, including how to introduce dependencies, initialize the agentweb object, load the web page, and handle the interactive event of the web page.
1. Introduce dependencies
First, add the following dependencies in the built.gradle file of your project:
dependencies {
implementation 'com.just.agentweb:agentweb:4.1.5'
}
2. Initialize the agentweb object
In your Activity or Fragment, create an Agentweb object and bind it to a view:
AgentWeb mAgentWeb = AgentWeb.with(this)
.setAgentWebParent(viewGroup, viewGroupLayoutParams)
.USEDEFAULTINDICATOR () // Use the default progress bar
.createAgentWeb()
.ready()
.go ("https://www.example.com"); // Load the specified web page
In the above code, Replace `ViewGroup` and` ViewGroupLayoutparams` is the parent layout and layout parameter of the Views that you want to bind Agentweb.
3. Load the web page
Agentweb provides a variety of ways to load the web page.For example, you can use the `GO (URL)" method to load the URL directly:
mAgentWeb.go("https://www.example.com");
You can also use the `GetUrlloader (). LoadUrl (url)` method to load a URL:
mAgentWeb.getUrlLoader().loadUrl("https://www.example.com");
You can also use the `getwebcreator (). Getwebview (). Loadurl (url)` method loads a URL:
mAgentWeb.getWebCreator().getWebView().loadUrl("https://www.example.com");
4. Treatment of interactive events on the web page
The Agentweb framework allows you to deal with the interactive incident of the web page in the Java code.For example, you can monitor the loading status of the page:
mAgentWeb.getWebCreator().getWebView().setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// Page start loading
}
@Override
public void onPageFinished(WebView view, String url) {
// Page loading complete
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// Page loading error
}
});
You can also listen to the click event on the page:
mAgentWeb.getWebCreator().getWebView().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// Page click Event processing logic
return false;
}
});
In addition, Agentweb also provides other rich listening methods and functions to meet different needs.
The above is the guideline of the Agentweb framework in the Java library.By introducing dependence, initialization Agentweb objects, loading web pages and processing the web page, you can easily embed Web pages in Android applications, and achieve rich interactive functions.I hope this article will help you!