当前位置: 代码迷 >> Android >> webview loadUrl 展示“找不到网页”
  详细解决方案

webview loadUrl 展示“找不到网页”

热度:368   发布时间:2016-04-28 05:00:24.0
webview loadUrl 显示“找不到网页”
MainActivity.java源码:
public class MainActivity extends ActionBarActivity {

    private EditText metAddress;
    private WebView mWebview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        metAddress = (EditText)findViewById(R.id.etAddress);
        mWebview = (WebView)findViewById(R.id.webview);
        mWebview.getSettings().setJavaScriptEnabled(true);
        Button btnBrowse = (Button)findViewById(R.id.btnSearch);
        btnBrowse.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                String address = metAddress.getText().toString();
                if (URLUtil.isNetworkUrl(address)) {
                             mWebview.loadUrl(address);
                } else {
                    Toast.makeText(getApplicationContext(), "请输入正确的网址.", Toast.LENGTH_LONG).show();
                }
            }
        });
    }

AndroidManifest.xml源码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="heproj.h1" >
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="heproj.h1.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="andorid.permission.INTERNET"/>
</manifest>
点击按钮时总是显示“找不到网页”,不知为何?
------解决方案--------------------
网络访问权限开了吗