Java 在 Android 应用程序中打开网页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18581850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening a webpage in an Android App
提问by Chris
I was wondering what you guys/gals would recommend in terms of opening a webpage inside an app (i.e a smaller window with a webpage open in it but not a web browser) Im trying to integrate my webpage into my app more or less. Thanks :)
我想知道你们/女孩在打开应用程序内的网页方面会推荐什么(即一个较小的窗口,其中打开一个网页但不是网络浏览器)我试图或多或少地将我的网页集成到我的应用程序中。谢谢 :)
采纳答案by matthewrdev
Have you tried using the WebViewlayout?
您是否尝试过使用WebView布局?
In your layout file:
在您的布局文件中:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Include the INTERNET
permission into your manifest:
将INTERNET
权限包含在您的清单中:
<uses-permission android:name="android.permission.INTERNET" />
And then in your Activity:
然后在您的活动中:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
This will embed a web-browser into your application (rather than open an external browser).
这会将 Web 浏览器嵌入到您的应用程序中(而不是打开外部浏览器)。
回答by Ranjithkumar
You can place you view group and then place the webview inside and modify size as needed
您可以放置视图组,然后将 webview 放入其中并根据需要修改大小
<LinearLayout
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</WebView>
</LinearLayout>
In your manifest file give the permission
在您的清单文件中授予权限
<uses-permission android:name="android.permission.INTERNET" />
then you get the object from code
然后你从代码中获取对象
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.google.com");