可以考虑去掉Scrillview看一下
代码如下
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
ohos:id="$+id:webview"
ohos:height="0fp"
ohos:weight="1"
ohos:width="match_parent">
ohos:height="100fp"
ohos:width="match_parent"
ohos:background_element="$color:blue"
ohos:text="tetxtx"
ohos:text_size="24vp"
ohos:text_alignment="center"/>
package com.example.jsdemo.slice;
import com.example.jsdemo.ResourceTable;
import com.example.jsdemo.utils.HiLogUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.webengine.*;
import ohos.media.image.PixelMap;
public class WebviewSlice extends AbilitySlice {
private static final String EXAMPLE_URL = "https://main.m.taobao.com/";
@Override
protected void onStart(Intent intent) {
super.onStart(intent);
setUIContent(ResourceTable.Layout_webview_slice);
WebView webView = (WebView) findComponentById(ResourceTable.Id_webview);
WebConfig webConfig = webView.getWebConfig();
webConfig.setJavaScriptPermit(true);
webConfig.setWebStoragePermit(true);
webConfig.setDataAbilityPermit(true);
webConfig.setLoadsImagesPermit(true);
webConfig.setMediaAutoReplay(true);
webConfig.setLocationPermit(true);
webConfig.setSecurityMode(WebConfig.SECURITY_SELF_ADAPTIVE);
webView.setWebAgent(new WebAgent() {
@Override
public void onLoadingPage(WebView webview, String url, PixelMap favicon) {
super.onLoadingPage(webview, url, favicon);
// 页面开始加载时自定义处理
HiLogUtils.PrintLog("onLoadingPage======>>>");
}
@Override
public void onPageLoaded(WebView webview, String url) {
super.onPageLoaded(webview, url);
// 页面加载结束后自定义处理
HiLogUtils.PrintLog("onPageLoaded======>>>");
}
@Override
public void onLoadingContent(WebView webview, String url) {
super.onLoadingContent(webview, url);
// 加载资源时自定义处理
HiLogUtils.PrintLog("onLoadingContent======>>>");
}
@Override
public void onError(WebView webview, ResourceRequest request, ResourceError error) {
super.onError(webview, request, error);
// 发生错误时自定义处理
HiLogUtils.PrintLog("onError======>>>"+error.getInfo());
}
});
webView.load(EXAMPLE_URL);
}
}
效果如图所示
可以考虑去掉Scrillview看一下
代码如下
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
ohos:id="$+id:webview"
ohos:height="0fp"
ohos:weight="1"
ohos:width="match_parent">
ohos:height="100fp"
ohos:width="match_parent"
ohos:background_element="$color:blue"
ohos:text="tetxtx"
ohos:text_size="24vp"
ohos:text_alignment="center"/>
package com.example.jsdemo.slice;
import com.example.jsdemo.ResourceTable;
import com.example.jsdemo.utils.HiLogUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.webengine.*;
import ohos.media.image.PixelMap;
public class WebviewSlice extends AbilitySlice {
private static final String EXAMPLE_URL = "https://main.m.taobao.com/";
@Override
protected void onStart(Intent intent) {
super.onStart(intent);
setUIContent(ResourceTable.Layout_webview_slice);
WebView webView = (WebView) findComponentById(ResourceTable.Id_webview);
WebConfig webConfig = webView.getWebConfig();
webConfig.setJavaScriptPermit(true);
webConfig.setWebStoragePermit(true);
webConfig.setDataAbilityPermit(true);
webConfig.setLoadsImagesPermit(true);
webConfig.setMediaAutoReplay(true);
webConfig.setLocationPermit(true);
webConfig.setSecurityMode(WebConfig.SECURITY_SELF_ADAPTIVE);
webView.setWebAgent(new WebAgent() {
@Override
public void onLoadingPage(WebView webview, String url, PixelMap favicon) {
super.onLoadingPage(webview, url, favicon);
// 页面开始加载时自定义处理
HiLogUtils.PrintLog("onLoadingPage======>>>");
}
@Override
public void onPageLoaded(WebView webview, String url) {
super.onPageLoaded(webview, url);
// 页面加载结束后自定义处理
HiLogUtils.PrintLog("onPageLoaded======>>>");
}
@Override
public void onLoadingContent(WebView webview, String url) {
super.onLoadingContent(webview, url);
// 加载资源时自定义处理
HiLogUtils.PrintLog("onLoadingContent======>>>");
}
@Override
public void onError(WebView webview, ResourceRequest request, ResourceError error) {
super.onError(webview, request, error);
// 发生错误时自定义处理
HiLogUtils.PrintLog("onError======>>>"+error.getInfo());
}
});
webView.load(EXAMPLE_URL);
}
}
效果如图所示
举报