更改网站时WebView无法更新 [英] WebView not updating when I change the website

查看:151
本文介绍了更改网站时WebView无法更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我已将我的网站链接到我的网络视图.但是,当我更新网站并重新启动应用程序时,所做的更改不会反映在应用程序上.这是我的代码:

So I have my website linked on to my web view. However, when I update my website and restart my app, the changes do not reflect on the app. Here is my code:

这是我的代码:

 package com.myworldrules.apps.lifehacks;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import  android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
private WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String url = "http://hacks.myworldrules.com";
    view=(WebView) this.findViewById(R.id.webView);
    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl(url);

    view.setWebViewClient(new WebViewClient());

}

}

AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myworldrules.apps.lifehacks">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:configChanges="orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Activity.main/xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
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"
tools:context="com.myworldrules.apps.lifehacks.MainActivity">

<WebView
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</android.support.constraint.ConstraintLayout>

请帮助我提供我的代码.

Please help me with my code.

推荐答案

将您的Java代码修改为-

Modify your java code as -

package com.myworldrules.apps.lifehacks;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import  android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
private WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String url = "http://hacks.myworldrules.com";
    view=(WebView) this.findViewById(R.id.webView);
    view.clearCache(true);
    WebSettings webSettings = view.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAppCacheEnabled(false);
    view.loadUrl(url);


    view.setWebViewClient(new WebViewClient());

}

}

这篇关于更改网站时WebView无法更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆