2011-01-25 63 views
0

在我的游戏中,我想要有一种“一天中的消息”功能。基本上,当用户点击主菜单中的“当天消息”按钮时,它将在游戏中打开浏览器视图。当用户完成时,他点击一个“关闭”按钮,视图消失,将他返回到游戏菜单。在Android上创建一个游戏中的Web浏览器

那么,是否有可能动态创建浏览器视图?如果是,如何?

回答

1

下可以在对话框中使用以及

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"); 
     } 
    } 
+0

会调用findViewById假设的WebView的布局已定义已地方?如果没有?它仍然有可能吗? – djcouchycouch 2011-01-25 15:19:56

0

你可能只是使用WebView。当你希望它显示出来时,你可以将其视图状态设置为View.VISIBLE。当您希望它消失时,只需将其视图状态设置为View.GONE即可。