我在游戏运行时正在开发游戏,我需要显示带有来自网络的一些指令的 WebView ,这可能吗?
这些指令将一次又一次地显示,并且是动态的,因为它们来自服务器。
你能帮我吗?我不能使用 LayoutBaseGameActivity,因为我不想总是显示它们。
我想暂停游戏并显示一个可点击的 WebView 。请帮忙。
最佳答案
您可以添加到您的游戏 Activity 以显示 WebView 并在需要时调用 openWebViewURL 或 openWebViewHTML
@Override
protected void onSetContentView() {
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT);
mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine, this);
final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
final FrameLayout.LayoutParams webViewLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, 100,
Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
webView = new WebView(this);
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
frameLayout.addView(webView, webViewLayoutParams);
this.setContentView(frameLayout, frameLayoutLayoutParams);
webView.setVisibility(webView.INVISIBLE);
}
private void openWebViewURL(String url) {
webView.loadUrl(url);
this.runOnUiThread(new Runnable() {
@Override
public void run() {
webView.setVisibility(webView.VISIBLE);
}
});
}
private void openWebViewHTML(String html) {
webView.loadData(html,"text/html", "en_US");
this.runOnUiThread(new Runnable() {
@Override
public void run() {
webView.setVisibility(webView.VISIBLE);
}
});
}
关于android - 在 Android 上运行游戏时在 AndEngine GLES 2 中显示 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16644424/