【发布时间】:2019-05-28 12:11:09
【问题描述】:
我正在尝试在胡椒机器人平板电脑的 webview 中显示网页。
在一个正在进行的项目中,已经使用按钮创建了 html 页面。当用户点击按钮时,我想在 webview 中显示“https://www.ebay.com/”网页。
它是机器人平台NAOqi与Android平板电脑连接,用户可以通过触摸点击按钮。
我创建了带有按钮和 webview 标签的 main.xml 文件 为按钮 onclick 创建了 Activity 为 webview 创建了另一个 Activity。
//bill.html page
<table class="billtab">
<tbody>
<tr>
<td align="center">
<div id="mPay" class="buttonstyle"
onclick="goToLoginPage();">mPay</div>
</td>
<td align="center">
<div id="ePay" class="buttonstyle" >Pay by ePay</div>
</td>
</tr>
</tbody>
</table>
--------------------------
/main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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" >
<Button
android:id="@+id/ePay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Go to https://www.epay.com/"
/>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
------------------------------------
//MainActivity.java
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.ePay);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, WebViewActivity.class);
startActivity(intent);
}
});
}
}
------------------------------
//webviewactivity.java
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.epay.com/");
}
}
-------------------------------
在 Pepper robo 平板电脑上,网页应显示在 webview 中
【问题讨论】:
-
您使用的是什么版本的机器人?您使用的是 Android QiSDK 还是 Choregraph?您是否必须在平板电脑上安装 Android 应用程序或通过 choregraph/python 打开网站也是一种选择?
-
NAOqi 版本 2.5.10.7 -- 我正在使用 choregraph -- 当用户点击按钮时,我可以通过 choregraph 打开网站(使用 javascript window.open() 函数)。但是网页必须在 webview 中显示。由于 webview 是 Android 组件,如何在 Pepper android 平板电脑中显示.. 请提出解决方法。谢谢
-
我认为该页面实际上已经显示在 webview 中。在 Choregraph 中,您调用了 ALTabletService::showWebview 或 ShowWebView Box?所以页面已经显示在 Webview 中。在那个 webview 中调用 window.open() 仍然是 webview ......你使用 android 编程的动机是什么?使用 2.5.10.7。它不受支持,可以用 choregraph/python/javascript 解决很多问题。