【问题标题】:Embedding a Web page in an Android App在 Android 应用程序中嵌入网页
【发布时间】:2014-12-27 10:30:16
【问题描述】:

我正在尝试在 Android 应用程序中嵌入网页。 以下是在我的应用程序的 main_activity java 文件中编写的代码。

package com.example.webpage;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WebView webview = new WebView(this);
        setContentView(webview);
        webview.loadUrl("http://www.google.com/");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

问题是每当我在模拟器中启动我的应用程序时,它都会显示“找不到页面”错误。 请帮帮我。

【问题讨论】:

  • 试试这个https://www.google.com
  • 您是否在清单中设置了 ?
  • 感谢 Moradiya Akash 和 MD。它有效。

标签: java android xml android-emulator webpage


【解决方案1】:

试试这个:

  1. 首先,获取 XML 格式的 webview。

  2. 像这样绑定它们:

    WebView webView = (WebView)findViewById(R.id.webView1);
    
  3. 然后这样做:

    String url = "http://www.google.com/";
    WebView webView = (WebView)findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    相关资源
    最近更新 更多