【问题标题】:webview in android not displaying contentandroid中的webview不显示内容
【发布时间】:2015-01-12 01:48:35
【问题描述】:

对于博客阅读器应用程序,当我尝试将活动内的树屋博客站点作为 web 视图查看时,该应用程序工作。但是当我尝试使用 iTunes url 或其他网站时,它不会显示我活动中的内容,而是打开 chrome。现在我不知道这是否正常,还是我必须为此添加一些代码,谢谢。下面是我正在实现 webview 的活动中的代码,谢谢

package com.paveynganpi.applestorefeed;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;


public class AppleFeedWebViewActivity extends ActionBarActivity {

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

    //get the intent from MainListActivity.java
    Intent intent = getIntent();
    Uri appleFeedUri = intent.getData();

    WebView webView = (WebView)findViewById(R.id.webView);
    webView.loadUrl(appleFeedUri.toString());

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_apple_feed_web_view, 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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

【问题讨论】:

    标签: android android-layout android-activity webview android-webview


    【解决方案1】:

    当 WebView 的 WebViewClient 为空时,它默认为这种行为(在浏览器中打开链接)。要将导航保留在 WebView 中,请执行以下操作:

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    

    【讨论】:

      【解决方案2】:

      检查您是否在 Android Manifest.xml 文件中拥有所需的权限

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

      如果提供了权限,那么唯一的原因可能是 URL

      添加Log语句查看URL的值

      Log.w("URL",appleFeedUri.toString());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多