栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在WebView上添加拉动刷新以刷新

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在WebView上添加拉动刷新以刷新

您可以像这样在Swipe Refesh布局中包装webview

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"app:layout_behavior="@string/appbar_scrolling_view_behavior"tools:context="com.vvhvb.hesselfeenstra.vvheerenveenseboys.MainActivity"tools:showIn="@layout/activity_main"><android.support.v4.widget.SwipeRefreshLayout    android:id="@+id/swipeContainer"    android:layout_width="match_parent"    android:layout_height="match_parent"    app:layout_behavior="@string/appbar_scrolling_view_behavior"><android.support.v4.widget.NestedScrollView    android:layout_width="match_parent"    android:layout_height="match_parent">    <WebView        android:id="@+id/webView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentBottom="true"        android:layout_alignParentEnd="true"        android:layout_alignParentLeft="true"        android:layout_alignParentRight="true"        android:layout_alignParentStart="true"        android:layout_alignParentTop="true" /></android.support.v4.widget.NestedScrollView></android.support.v4.widget.SwipeRefreshLayout></RelativeLayout>

在java中

package com.vvhvb.hesselfeenstra.vvheerenveenseboys;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.webkit.WebView;import android.webkit.WebViewClient;public class MainActivity extends AppCompatActivity {WebView view;SwipeRefreshLayout mySwipeRefreshLayout;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    mySwipeRefreshLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeContainer);    String url ="http://heerenveenseboys.nl/";    view=(WebView) this.findViewById(R.id.webView);    view.getSettings().setJavascriptEnabled(true);    view.getSettings().setBuiltInZoomControls(true);    view.getSettings().setDisplayZoomControls(false);    view.setWebViewClient(new WebViewClient());    view.loadUrl(url);    mySwipeRefreshLayout.setonRefreshListener(    new SwipeRefreshLayout.onRefreshListener() {    @Override    public void onRefresh() {        view.reload();    }    }    );}}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/437916.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号