WebView使用注意事项

本文详细介绍了WebView的各种高级配置选项,包括如何通过设置使WebView更好地适应屏幕尺寸、解决加载问题及实现与JavaScript的交互。此外,还探讨了支付链接跳转、图片上传以及与SwipeRefreshLayout结合使用时的注意事项。

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

onReceivedError方法:在方法中进行判断处理,比如说load错误页面


mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true;

//html里多宽(一行的文字多长)webview就多宽,就是说要展示满满的一行文字
setLoadWithOverviewMode(true) loads the WebView completely zoomed out

//自动换行,手机多宽,webview就多宽
setUseWideViewPort(true) makes the Webview have a normal viewport (such as a normal desktop browser), while when false the webview will have a viewport constrained to its own dimensions (so if the webview is 50px*50px the viewport will be the same size)

两个一起用,webview里一行展示不出来,那就需要suoxiao


js和java代码的互相调用:
https://juejin.im/entry/57b586d35bbb50006303c7e7
http://www.jianshu.com/p/55512b523178
http://www.jianshu.com/p/415af04b5891


调用支付宝支付时的问题:

if (url.startsWith("http:") || url.startsWith("https:")) {
    view.loadUrl(url);   
    //在当前的webview中跳转到新的url
     return true;
} else {
    mOtherJump = true;
}
try {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
    } catch (Exception e) {
         return true;
    }

上传图片:http://blog.youkuaiyun.com/worst_hacker/article/details/62416755


和SwipeRefreshLayout结合使用的问题:
http://blog.youkuaiyun.com/worst_hacker/article/details/62226183


关于在浏览器中使用scheme方式打开app

<activity android:name=".ui.GuideActivity">
            <intent-filter>
                <data
                    android:host="com.yxjy.baonaer"
                    android:scheme="baonaer" />
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>
 <a href="baonaer://com.yxjy.baonaer">跳转app</a>

Android M中新添加的app-links
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0718/3200.html

webview播放audio问题:
http://stackoverflow.com/questions/15946183/android-webview-html5-video-autoplay-not-working-on-android-4-0-3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值