package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class MainActivity1 extends Activity{
EditText urlEditText;
WebView showView;
Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
urlEditText = (EditText)findViewById(R.id.url);
showView = (WebView)findViewById(R.id.show);
WebSettings settings = showView.getSettings();
//适应屏幕
settings.setUseWideViewPort(true);
settings.setSupportZoom(true);
// settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
// settings.setLoadWithOverviewMode(true);
// settings.setBuiltInZoomControls(true);
settings.setJavaScriptEnabled(true);
showView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url)
{ // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边
view.loadUrl(url);
return true;
}
});
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String urlStr = urlEditText.getText().toString();
if(urlStr.startsWith("http://www.")){
showView.loadUrl(urlStr);
} else if(urlStr.startsWith("www.")){
showView.loadUrl("http://"+urlStr);
} else {
showView.loadUrl("http://www."+urlStr);
}
}
});
}
}
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class MainActivity1 extends Activity{
EditText urlEditText;
WebView showView;
Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
urlEditText = (EditText)findViewById(R.id.url);
showView = (WebView)findViewById(R.id.show);
WebSettings settings = showView.getSettings();
//适应屏幕
settings.setUseWideViewPort(true);
settings.setSupportZoom(true);
// settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
// settings.setLoadWithOverviewMode(true);
// settings.setBuiltInZoomControls(true);
settings.setJavaScriptEnabled(true);
showView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url)
{ // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边
view.loadUrl(url);
return true;
}
});
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String urlStr = urlEditText.getText().toString();
if(urlStr.startsWith("http://www.")){
showView.loadUrl(urlStr);
} else if(urlStr.startsWith("www.")){
showView.loadUrl("http://"+urlStr);
} else {
showView.loadUrl("http://www."+urlStr);
}
}
});
}
}