我可以浏览" index.html" 页面。当我在页面的某个链接中尝试回到主页,即" index.html" ...显示白色屏幕
一直在寻找解决方案,但徒劳无功。
package com.veereshc.veer.vturesults;
import android.content.Context;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import java.io.IOException;
import java.io.InputStream;
public class MainActivity extends ActionBarActivity {
WebView webView;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView = new WebView(this);
context = this;
WebViewClient client = new WebViewClient();
webView.setWebViewClient(client);
setContentView(webView);
try {
InputStream stream = this.getAssets().open("index.html");
int streamSize = stream.available();
byte[] buffer = new byte[streamSize];
stream.read(buffer);
stream.close();
String html = new String(buffer);
webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null);
}
catch (IOException e){
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
根据您当前的代码,我可以说您不需要设置客户端。删除这两行,你的webview应该按预期工作,即没有空白屏幕。
WebViewClient client = new WebViewClient();
webView.setWebViewClient(client)