如何在启动时在Android应用程序中打开网页 [英] how to open webpage within android app in startup
问题描述
嗨朋友们,
我不会创建一个简单的Android应用程序。问题是如果我打开应用程序然后在启动时应用程序应该在应用程序中打开像www.google.com这样的URL,而不是在任何默认浏览器中使用类似的Web视图控件。所以请给我一个代码
提前谢谢,我希望我会得到很好的结果
Hi friends,
I wont to create a simple android app. The thing is if i open the application then in the start up the application should open the URL like www.google.com with in the application only not in a any default browser by using like web view control. So please provide me a code
Thanks in advance and i hope i will get good result
推荐答案
Web视图控件一般用来打开应用程序中的任何URL。因此,您不必移动到其他应用程序,如内置浏览器或Chrome等。
根据文档:
如果要将Web应用程序(或仅仅是网页)作为客户端应用程序的一部分提供,可以使用WebView进行。
参见示例,
布局:
Web view control is generally used to open any URL within your application. Therefore you don't have to move to the other application like inbuilt browser, or chrome etc.
As per the Documentation :
If you want to deliver a web application (or just a web page) as a part of a client application, you can do it using WebView.
See the example,
layout :
<webview xmlns:android="http://schemas.android.com/apk/res/android">
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</webview>
java:
java :
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
和最后清单:
and last Manifest:
<manifest ...="">
<uses-permission android:name="android.permission.INTERNET" xmlns:android="#unknown" />
...
</manifest>
您可以查看 example [ ^ ]。 :)
-KR
You can look at the example[^] as well. :)
-KR
main.xml的代码
code for main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="match_parent"
android:layout_height="match_parent">
<webview xmlns:android="http://schemas.android.com/apk/res/android">
android:id="@+id/wvBrowser"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</webview></linearlayout>
和mainactivity.java的代码
And code for mainactivity.java
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
WebView ourBrow=(WebView) findViewById(R.id.wvBrowser);
ourBrow.getSettings().setJavaScriptEnabled(true);
ourBrow.getSettings().setLoadWithOverviewMode(true);
ourBrow.getSettings().setUseWideViewPort(true);
ourBrow.setWebViewClient(new ourViewClient());
ourBrow.loadUrl("http://www.google.com");
}
}
创建myViewClient.java类并在myViewClient.java上复制以下代码
And after create a " ourViewClient.java " class and copy the below code on ourViewClient.java
package com.example.app;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class ourViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView v, String url)
{
v.loadUrl(url);
return true;
}
}
就是这样,享受。
现在,您的应用可以在您的应用中运行任何类似YouTube或JavaScript网页的网站。并且它不会打开任何用于加载网页的浏览器。
这篇关于如何在启动时在Android应用程序中打开网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!