首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android上创建游戏中的Web浏览器

在Android上创建游戏中的Web浏览器
EN

Stack Overflow用户
提问于 2011-01-25 22:25:03
回答 3查看 326关注 0票数 0

在我的游戏中,我希望有一种“当日消息”的功能。基本上,当用户点击主菜单中的“当日消息”按钮时,就会在游戏中打开一个浏览器视图。当用户完成后,他点击“关闭”按钮,视图消失,返回到游戏菜单。

那么,动态创建浏览器视图是可能的吗?如果是,是如何实现的?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-01-25 23:06:35

也可以在对话框中使用以下内容

代码语言:javascript
复制
    public void setWebView() {
//WebViewClient is used if you want to capture stuff from the webview, like if a link was pressed
                WebViewClient yourWebClient = new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        open_web = true;
                        if (!url.startsWith("http://") && !url.startsWith("https://")) {
                                url = "http://" + url;
                        }
                        Intent browserIntent = new Intent("android.intent.action.VIEW",
                                Uri.parse(url));
                        startActivity(browserIntent);
                        return true;
                    }
                };
                WebView wv = (WebView) findViewById(R.id.webview);
                wv.setWebViewClient(yourWebClient);
                String str = getHtml();
                wv.loadData(str, "text/html", "utf-8");
                wv.setBackgroundColor(0);
    }

    boolean isAsset = false;

    private String getHtml(){
        InputStream source = null;
        if (isAsset){
            source = getAssets().open("motd.html");
        } else {
            source = new FileInputStream(Environment.getExternalStorageDirectory() + "motd.html");
        }
    }
票数 1
EN

Stack Overflow用户

发布于 2011-01-25 23:04:23

您可能只需要使用WebView。当你想让它显示时,你只需要将它的视图状态设置为View.VISIBLE,当你想让它消失时,你只需要将它的视图状态设置为View.GONE即可。

票数 0
EN

Stack Overflow用户

发布于 2011-01-25 23:04:40

您可以在游戏中动态添加/删除WebView (或显示/隐藏它,随您的喜好)。

有关更多信息,请参阅WebView教程:

http://developer.android.com/resources/tutorials/views/hello-webview.html

请确保在布局中为“关闭”按钮留出空间,即您不想将布局高度设置为"fill_parent“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4794590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档