布局文件<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:weightSum="1">    <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1">        <requestFocus></requestFocus>    </EditText>    <LinearLayout     android:orientation="horizontal"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    >    <Button android:text="确定" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>    <Button android:text="取消" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>     </LinearLayout>  <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="match_parent"></WebView></LinearLayout>
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.Toast;public class Mp3infoActivity extends Activity {    /** Called when the activity is first created. */       private Button button_Ok,button_Reset;    private WebView webView;    private EditText editText;    private WebSettings webSettings;    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        button_Ok=(Button)findViewById(R.id.button1);        button_Reset=(Button)findViewById(R.id.button2);        webView=(WebView)findViewById(R.id.webView1);        webSettings=webView.getSettings();        webSettings.setJavaScriptEnabled(true);//支持JS        webSettings.setUseWideViewPort(true);////让浏览器支持用户自定义view        webSettings.setBuiltInZoomControls(true);//支持缩放        webSettings.setAllowFileAccess(true);//允许访问android系统数据文件        editText=(EditText)findViewById(R.id.editText1);                button_Ok.setOnClickListener(new ButtonListenr());        button_Reset.setOnClickListener(new ButtonListenr());                   }    private class ButtonListenr implements OnClickListener{@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.button1:String stringUrl=editText.getText().toString();stringUrl=stringUrl.trim();//去掉空格if (stringUrl.length()==0) {Toast.makeText(getApplicationContext(), "网址为空", Toast.LENGTH_LONG).show();}else {stringUrl="http://ting.baidu.com/search?key="+stringUrl;webView.loadUrl(stringUrl);}break;            case R.id.button2:            editText.setText(null);            break;default:break;}}        } }
上图

   

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. android 代码混淆总结
  4. Android(安卓)Studio编译问题:ProcessException: org.gradle.proc
  5. Android-->build.gradle-->packagingOptions,splits
  6. android 动画2
  7. Android之SharedPreferences权限
  8. Android加载html实现文件上传功能
  9. ImageView

随机推荐

  1. Android中的Surface和SurfaceView
  2. AsyncTask的使用方法(异步任务的处理)
  3. Android的 getSystemService
  4. Android(安卓)Camera HAL3 - MultiCamera
  5. js将一个数组传给android
  6. Android中设计具有背景图的按钮—ImageBu
  7. 【Android】adb常用指令整理
  8. Android SDK 中文 (56) ―― ViewFlipper
  9. android:editable和android:enabled的区
  10. android TextView中多个空格只显示一个