隐藏webview中的文本

本文介绍了一种通过修改HTML代码来隐藏网页中特定元素的方法,利用JavaScript进行页面结构的动态调整,实现对id为'login'的元素进行隐藏,适用于需要定制化显示效果的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 思路:将整个文档获取到,然后更改网页的结构,找到你想要隐藏的元素id,class。将其替换成html.replace("id=\"login\"", "style=\"display:none;\"");即可。

 

      private void getHtml_data(final String Url) {

 


HttpUtils httpUtils = new 
HttpUtils();
httpUtils.configSoTimeout(6000);
httpUtils.configTimeout(6000);
httpUtils.configCurrentHttpCacheExpiry(0);
RequestParams requestParams = new 


RequestParams();
requestParams.addHeader("user-Agent", 


"CMREADBC_AndroidNewspaper_tybb_480*800_V1.6.1


(480*800;Xiaomi;HM NOTE 1LTETD;Android4.4;cn;);");
requestParams.addHeader("need_round_news", 


"0");
requestParams.addHeader("Accept-Encoding", 


"gzip");
requestParams.addHeader("thin", "1");
// requestParams.addHeader("Host", 


"wap.cmread.com");
requestParams.addHeader("Connection", " Keep-


Alive");


httpUtils.send(HttpMethod.POST, Url, 


requestParams, new RequestCallBack<String>() {


@Override
public void onFailure(HttpException 


arg0, String arg1) {
Log.e("hyy", arg0.toString());
}


@Override
public void onSuccess


(ResponseInfo<String> responseInfo) {
try {
String html = 


responseInfo.result;
String text = 


html.replace("id=\"login\"", "style=\"display:none;\"");



webView.loadDataWithBaseURL("", text, "text/html", "utf-8", 


null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值