基于webview的应用程序不会启动该网站

时间:2014-04-17 15:25:38

标签: android webview

为了开始学习网络应用程序的工作方式,我编写了一个简单的网络应用程序,只需在应用程序启动时启动www.yahoo.com。但问题是,尽管设备连接到互联网并且我在清单文件中添加了互联网权限,但是当我运行应用程序时,网站无法加载或启动。请帮助找到错误或缺少的内容

JavaCode:

public class WebAppTest00 extends ActionBarActivity {

WebView webview00;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_app_test00);

    webview00 = (WebView) findViewById(R.id.webview00);
    webview00.getSettings().setJavaScriptEnabled(true);
    webview00.loadUrl("http://www.yahoo.com");

    /*if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }*/
}

XMLCode:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.webapptest00.WebAppTest00$PlaceholderFragment" >

<WebView 
    android:id="@+id/webview00"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

将http://添加到您的网址

应为http://www.yahoo.com

答案 1 :(得分:0)

请将这些权限添加到清单文件中,并且不要忘记在URL前加上“http://”;

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />