WebView
1. Feature Description
RemoteWebView is a component for loading and displaying web pages, corresponding to ViewType.WEB_VIEW. By setting a complete URL, it renders the corresponding page on Pilot. It fits embedding online help docs, live data dashboards, H5 pages, etc.
Create it via RemoteViewHelper.createWebView():
val webView = helper.createWebView()
2. Common Properties
The following properties are set via the corresponding setXxx() methods. Unless noted otherwise, if the component is already mounted, call syncToRemote() after changing a property to make it take effect on Pilot.
Size & Layout (inherited from RemoteViewProvider)
| Method | Params | Description |
|---|---|---|
setWidth | Int | Width (dp); special values RemoteView.MATCH_PARENT(-1) / WRAP_CONTENT(-2) |
setHeight | Int | Height (dp); same special values |
setMinSize | minWidth: Int, minHeight: Int | Minimum size (dp) |
setPadding | left, top, right, bottom: Int | Padding (dp) |
setVisibility | VisibilityType | Visibility: VISIBLE / INVISIBLE / GONE |
setAlpha | Float | Opacity, 0.0 – 1.0 |
setEnabled | Boolean | Whether enabled |
Background & Shape (inherited from RemoteViewProvider)
| Method | Params | Description |
|---|---|---|
setBackground | Int | Solid background color (ARGB Int) |
setBackgroundShape | ShapeDescriptor | Background shape: fill / stroke / corner radius |
Web Properties
| Method | Params | Description |
|---|---|---|
setUrl | String | URL to load (must be a complete http / https address) |
3. Tips
- The URL must be a complete address.
setUrlrequires a full address with the protocol scheme (e.g.https://www.dji.com); do not pass justwww.dji.comor a relative path, otherwise it cannot load. - Give the WebView explicit width and height. Specify a definite size with
setWidth/setHeight(e.g.MATCH_PARENTwidth + fixed height150) to avoid size collapse that makes the page invisible or renders abnormally. - Background color must be ARGB Int.
setBackgroundaccepts an Int color value. Do not pass"#RRGGBB","0xAARRGGBB", orR.color.xxx. - Call
syncToRemote()after changing a mounted component's properties.setXxxonly updates the local cache;syncToRemote()batch-syncs to Pilot. If you configure properties before mounting, no extra call is needed.
4. Sample Code
In each group below, the code sample is on the left and the corresponding Pilot-side rendered preview is on the right.
01 Component Types (load a web page)
// Load a web page: complete URL + explicit size
val webView = helper.createWebView().apply {
setWidth(RemoteView.MATCH_PARENT)
setHeight(150)
setUrl("https://developer.dji.com/doc/mobile-sdk-tutorial/en/")
}
For a full runnable example, see drawing/WebViewDrawer.kt in the official Sample
open-pilot-plugin-sample.