-
打开官网,找到WebView的文档(模拟器不支持)
鸿蒙webview的开发指南(原始链接,方便大家识别并点击):https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ui-java-component-webview-0000001092715158
2. 创建一个Page Ability,把基本布局弄好
下面是代码
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
<DirectionalLayout
ohos:height="30vp"
ohos:width="match_parent"
ohos:orientation="horizontal">
<TextField
ohos:id="$+id:text_webView_Url"
ohos:height="match_content"
ohos:width="match_parent"
ohos:background_element="$graphic:background_ability_simple_web_view"
ohos:focus_border_enable="true"
ohos:hint="请输入网址"
ohos:max_text_lines="1"
ohos:multiple_lines="false"
ohos:scrollable="true"
ohos:text="www.harmonyos.com"
ohos:text_size="50"
ohos:weight="1"
/>
<Button
ohos:id="$+id:button_webview_surf"
ohos:height="match_content"
ohos:width="60vp"
ohos:background_element="$graphic:button_element"
ohos:text="跳转"
ohos:text_size="50"/>
</DirectionalLayout>
<ProgressBar
ohos:id="$+id:other_webView_progressBar"
ohos:height="10vp"
ohos:width="match_parent"
ohos:visibility="hide">
</ProgressBar>
<ohos.agp.components.webengine.WebView
ohos:id="$+id:webview_webview_webview"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:weight="1">
</ohos.agp.components.webengine.WebView>
<DirectionalLayout
ohos:height="30vp