如何加载新的 Activity onclick
当我单击在 WebView 中显示的 HTML 页面内部时,如何更改 Activity 、加载新 Activity 。 Demo.html 在资产中。如何加载新的Activity? 这是资产内的 Demo.html
<html>
<script language="javascript">
/* This function is invoked by the activity */
function wave() {
alert("1");
//What to do to change on new Activity
alert("2");
}
</script>
<body>
<!-- Calls into the javascript interface for the activity -->
<a onClick="window.demo.clickOnAndroid()">
<div style="width:80px;
margin:0px auto;
padding:10px;
text-align:center;
border:2px solid #202020;" >
<input id="test" type="button" onclick="wave">Click Me!</button>
</div></a>
</body>
</html>
当我单击 id="test" 的按钮时该怎么办我会转到 android 应用程序中的新活动,就像我在 android 中使用 Button 时而不是在 JavaScript 中以正常方式所做的那样
Intent i = new Intent(getApplicationContext(), Test.class);
startActivity(i);
How to change Activity , load new Activity, when I click on inside HTML page which I shows inside WebView. Demo.html is in assets. How to load new Activity ?
This is Demo.html inside assets
<html>
<script language="javascript">
/* This function is invoked by the activity */
function wave() {
alert("1");
//What to do to change on new Activity
alert("2");
}
</script>
<body>
<!-- Calls into the javascript interface for the activity -->
<a onClick="window.demo.clickOnAndroid()">
<div style="width:80px;
margin:0px auto;
padding:10px;
text-align:center;
border:2px solid #202020;" >
<input id="test" type="button" onclick="wave">Click Me!</button>
</div></a>
</body>
</html>
What to do so when I click on button with id="test" I go to new activity in android app, like I do in normal way when use Button in android, not in JavaScript
Intent i = new Intent(getApplicationContext(), Test.class);
startActivity(i);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确(意味着单击按钮时启动一个新的活动),您应该在此处查看完整的指南:http://developer.android.com/guide/webapps/webview.html,更具体地说是“将 JavaScript 代码绑定到 Android 代码”部分。尝试一下,如果有任何问题请再次回来。希望这有帮助!
If I have understand correct (meaning start a new Activity when clicking on the button) you should check here for a complete guide: http://developer.android.com/guide/webapps/webview.html and more specifically the section 'Binding JavaScript code to Android code'. Try this and if you have any problem come back again. Hope this helps!
看看这个。WebView 可以做什么在 Android 中做什么?。本博客展示了如何通过 JavaScript 调用 Android 活动或方法。
Have a look at this.What WebView can do in Android ?. This blog shows how to call an android activity or method via javascript.