使用此代码,当我滚动时,比如10%,禁用web.reload();而对于一个,因为我变量String的url of shouldOverrideUrlLoading在变量String XYvariable中超出了上面的例子。
package ru.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
TextView TEXT;
String XYvariable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView web = (WebView) findViewById(R.id.webView);
web.loadUrl("http://example.com/string.html");
web.getSettings().setJavaScriptEnabled(true);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
web.reload();
}
}, 1000, 1000);
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String Cur = (String) url.substring(23);
String Link = (String) url.substring(16,23);
String XY = (String) url; // Post varriable up in string XYvariable
setContentView(R.layout.vot);
TEXT = (TextView) findViewById(R.id.textView);
switch (Link){
case "id_user":
TEXT.setText(Cur+" / user");
break;
case "id_mess":
TEXT.setText(Cur + " / messages");
break;
}
return true;
}
});
}
public boolean onCreateOptionsMenu (Menu menu){
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ru.MainActivity">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
事先谢谢大家! ))