我有图像显示在本地 HTML 页面中,并且有一个用于单击事件的按钮。单击此按钮时,我需要调用另一个活动。它正在工作。但问题是在另一个之后返回到 HTML 页面,图像没有显示并且应用程序无法正常工作。
<script language="javascript">
function validClick() {
valid.performClick();
document.getElementById("ok").value = "start";
}
function refuseClick(){
refuse.performClick();
document.getElementById("no").value = "Je refuse";
}
<div>
<button type="button" id="ok"
style="font-weight: 700; margin-right: 20px;" onclick="validClick();">Start</button>
</div>
HTML 页面包含图像:
<li><a class="box" href="products.html" data-transition="fade" > <img src="img/products.png" alt="Products"> <span class="text"> Products</span>
主要活动:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.about_screen);
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/index.html");
valid = new Button(this);
valid.setOnClickListener(this);
refuse = new Button(this);
refuse.setOnClickListener(this);
// Enablejavascript
WebSettings ws = webview.getSettings();
ws.setJavaScriptEnabled(true);
// Add the interface to record javascript events
webview.addJavascriptInterface(valid, "valid");
webview.addJavascriptInterface(refuse, "refuse");
}
@Override
public void onClick(View v) {
if (v.equals(valid)) {
Intent i = new Intent(this, CloudReco.class);
startActivity(i);
} else if (v.equals(refuse)) {
//do Something else }
}