gpt4 book ai didi

android - 在 Android 上运行游戏时在 AndEngine GLES 2 中显示 webview

转载 作者:行者123 更新时间:2023-11-29 14:15:37 27 4
gpt4 key购买 nike

我在游戏运行时正在开发游戏,我需要显示带有来自网络的一些指令的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com