?uses-permission android:name="android.permission.INTERNET"? 别忘了啊
public class WebPageBackgroundColorBridgeActivity extends Activity { private static final String TAG = "WebPageBackgroundColorBridgeActivity"; private static final int OPAQUE = 0x00FFFFFF; private EditText url; private WebView webView; private Button go; private SeekBar colorBar; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); url = (EditText) findViewById(R.id.url); go = (Button) findViewById(R.id.go); webView = (WebView) findViewById(R.id.webview); colorBar = (SeekBar) findViewById(R.id.colorbar); // 浏览器的选择 webView.setWebViewClient(new WebViewClient() { /* (non-Javadoc) * @see android.webkit.WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String) */ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { WebPageBackgroundColorBridgeActivity.this.url.setText(url); load(); return true; } }); webView.getSettings().setJavaScriptEnabled(true); // ENTER 按键 url.setOnKeyListener(new OnKeyListener() { public boolean onKey(View arg0, int key, KeyEvent arg2) { if ( key == KeyEvent.KEYCODE_ENTER ) { load(); return true; } return false; } }); // load page when we click go go.setOnClickListener(new OnClickListener() { public void onClick(View v) { load(); } }); // 改变颜色 colorBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { float p100 = progress / 100.0f; webView.loadUrl(String.format( "javascript:{document.body.style.backgroundColor='#%06x'}", Color.HSVToColor(new float[] {360 * p100, p100, 1 - p100 }) & OPAQUE)); } public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); load(); } private void load() { webView.loadUrl(url.getText().toString()); webView.requestFocus(); } /* (non-Javadoc) * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent) */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { webView.goBack(); return true; } return super.onKeyDown(keyCode, event); } }
?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent"> <EditText android:layout_height="wrap_content" android:id="@+id/url" android:scrollHorizontally="true" android:text="@string/home_url" android:layout_width="wrap_content" android:singleLine="true" android:layout_weight="1"></EditText> <Button android:layout_height="wrap_content" android:text="@string/go" android:layout_toRightOf="@id/url" android:id="@+id/go" android:layout_width="wrap_content"></Button> </LinearLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <WebView android:id="@+id/webview" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent"></WebView> <SeekBar android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_above="@id/webview" android:layout_alignBottom="@id/webview" android:layout_alignParentBottom="true" android:layout_margin="12dip" android:id="@+id/colorbar"></SeekBar> </RelativeLayout> </LinearLayout>
?这里注意和http://wang-peng1.iteye.com/admin/blogs/631899
当中浏览器的区别
本实例的浏览器是使用新的浏览器不用原来的 给的链接是一直使用一个