MainActivity.java源码:
publicclassMainActivityextendsActionBarActivity{
privateEditTextmetAddress;
privateWebViewmWebview;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
metAddress=(EditText)findViewById(R.id.etAddress);
mWebview=(WebView)findViewById(R.id.webview);
mWebview.getSettings().setJavaScriptEnabled(true);
ButtonbtnBrowse=(Button)findViewById(R.id.btnSearch);
btnBrowse.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
Stringaddress=metAddress.getText().toString();
if(URLUtil.isNetworkUrl(address)){
mWebview.loadUrl(address);
}else{
Toast.makeText(getApplicationContext(),“请输入正确的网址.”,Toast.LENGTH_LONG).show();
}
}
});
}
AndroidManifest.xml源码:
package=”heproj.h1″>
android:allowBackup=”true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”>
android:name=”heproj.h1.MainActivity”
android:label=”@string/app_name”>
点击按钮时总是显示“找不到网页”,不知为何?
解决方案:25分
网络访问权限开了吗