1.xml代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bj"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/btnSearch"
android:layout_toRightOf="@+id/etWord"
android:layout_marginLeft="10dip"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:layout_weight="1"
android:background="@drawable/an"
android:οnclick="CheckWord"
android:onClick="searchWord" />
<EditText
android:id="@+id/etWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@android:drawable/edit_text"
android:ems="10"
android:singleLine="true"
android:textColor="#552006"
android:textColorHint="#782f10" />
<WebView
android:id="@+id/wvSearchResult"
android:layout_width="fill_parent"
android:layout_height="120dip"
android:layout_alignParentBottom="true"
android:layout_below="@id/etWord"
android:layout_marginTop="10dip"
android:layout_weight="1" />
</RelativeLayout>
2.mainactivity 代码
public void CheckWord(View view){ String etURL=etWord.getText().toString(); etURL=etURL.trim(); if(!TextUtils.isEmpty(etURL)){ String path="http://dict.youdao.com/m/search?keyfrom=dict.mindex&q="+etURL; wvView.loadUrl(path); wvView.setWebViewClient(new HelloWebViewClient ()); }else{ Toast.makeText(this, "请填写单词", Toast.LENGTH_LONG).show(); } } private class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }
3.AndroidManifest.xml 添加网络权限
<uses-permission android:name="android.permission.INTERNET" />