From 58c01147faff729d983d85dfb1d4bedd74c7fd4f Mon Sep 17 00:00:00 2001 From: shutao Date: Mon, 29 Jul 2024 20:04:12 +0800 Subject: [PATCH] =?UTF-8?q?update=20unielement.md=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/dom/unielement.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/dom/unielement.md b/docs/dom/unielement.md index 6b09f7f8..e262baea 100644 --- a/docs/dom/unielement.md +++ b/docs/dom/unielement.md @@ -124,6 +124,8 @@ app平台 getAttribute 不支持获取 class、style 属性, uvue/vue 页面 +**getAndroidView获取原生View:** + ```uts //通过elementId 获取到UniElement对象 const element = uni.getElementById(elementId) @@ -145,19 +147,21 @@ if(element != null) { +**getAndroidView通过泛型定义获取原生View:** + ```uts -//通过elementId 获取web-view便签的UniElement对象 -const element = uni.getElementById(elementId) +//通过webViewElementId 获取web-view标签的UniElement对象 +const webViewElement = uni.getElementById(webViewElementId) //getElementById设置泛型为安卓底层WebView对象, 直接获取WebView 如果泛型不匹配会返回null -if(element != null) { - const webview = element.getAndroidView() +if(webViewElement != null) { + const webview = webViewElement.getAndroidView() } ``` #### 可通过getAndroidView泛型明确定义View类型的组件 -| 组件 | android平台原生View类型 | -| --------- | ------------------------------ | +| 组件 | 对应 android 平台原生View | +| --------- | -------------------------------- | | [view](https://doc.dcloud.net.cn/uni-app-x/component/view.html) | [ViewGroup](https://developer.android.google.cn/reference/android/view/ViewGroup) | | [input](https://doc.dcloud.net.cn/uni-app-x/component/input.html) | [EditText](https://developer.android.google.cn/reference/android/widget/EditText) | | [textarea](https://doc.dcloud.net.cn/uni-app-x/component/textarea.html) | [EditText](https://developer.android.google.cn/reference/android/widget/EditText) | -- GitLab