在我的游戏中,我希望有一种“当日消息”的功能。基本上,当用户点击主菜单中的“当日消息”按钮时,就会在游戏中打开一个浏览器视图。当用户完成后,他点击“关闭”按钮,视图消失,返回到游戏菜单。
那么,动态创建浏览器视图是可能的吗?如果是,是如何实现的?
发布于 2011-01-25 23:06:35
也可以在对话框中使用以下内容
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");
}
}发布于 2011-01-25 23:04:23
您可能只需要使用WebView。当你想让它显示时,你只需要将它的视图状态设置为View.VISIBLE,当你想让它消失时,你只需要将它的视图状态设置为View.GONE即可。
发布于 2011-01-25 23:04:40
您可以在游戏中动态添加/删除WebView (或显示/隐藏它,随您的喜好)。
有关更多信息,请参阅WebView教程:
http://developer.android.com/resources/tutorials/views/hello-webview.html
请确保在布局中为“关闭”按钮留出空间,即您不想将布局高度设置为"fill_parent“。
https://stackoverflow.com/questions/4794590
复制相似问题