MainActivity.java
- package com.example.youdaodictionary;
- import android.app.Activity;
- import android.os.Bundle;
- import android.text.TextUtils;
- import android.view.Menu;
- import android.view.View;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- private EditText etWord;
- private WebView wvResult;
- private WebView wvResult1;
- private WebView wvResult2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- initViews();
- initViews1();
- initViews2();
- }
- private void initViews() {
- etWord = (EditText) findViewById(R.id.etWord);
- wvResult = (WebView) findViewById(R.id.wvSearchResult);
- wvResult.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- view.loadUrl(url);
- return true;
- }
- });
- }
- private void initViews1() {
- wvResult1 = (WebView) findViewById(R.id.wvSearchResult1);
- wvResult1.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- view.loadUrl(url);
- return true;
- }
- });
- }
- private void initViews2() {
- wvResult2 = (WebView) findViewById(R.id.wvSearchResult2);
- wvResult2.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- view.loadUrl(url);
- return true;
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- public void searchWord(View view) {
- String word = etWord.getText().toString();
- if (TextUtils.isEmpty(word)) {
- Toast.makeText(this, "查询内容不能为空!", Toast.LENGTH_LONG).show();
- } else {
- final String strUrl = "http://dict.baidu.com/s?wd="
- + word;
- final String strUrl1= "http://www.iciba.com/"
- + word;
- final String strUrl2= "http://dict.youdao.com/m/search?keyfrom=dict.mindex&vendor=&q="
- + word;
- wvResult.loadUrl(strUrl);
- wvResult1.loadUrl(strUrl1);
- wvResult2.loadUrl(strUrl2);
- }
- }
- }
package com.example.youdaodictionary;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText etWord;
private WebView wvResult;
private WebView wvResult1;
private WebView wvResult2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
initViews1();
initViews2();
}
private void initViews() {
etWord = (EditText) findViewById(R.id.etWord);
wvResult = (WebView) findViewById(R.id.wvSearchResult);
wvResult.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
private void initViews1() {
wvResult1 = (WebView) findViewById(R.id.wvSearchResult1);
wvResult1.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
private void initViews2() {
wvResult2 = (WebView) findViewById(R.id.wvSearchResult2);
wvResult2.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void searchWord(View view) {
String word = etWord.getText().toString();
if (TextUtils.isEmpty(word)) {
Toast.makeText(this, "查询内容不能为空!", Toast.LENGTH_LONG).show();
} else {
final String strUrl = "http://dict.baidu.com/s?wd="
+ word;
final String strUrl1= "http://www.iciba.com/"
+ word;
final String strUrl2= "http://dict.youdao.com/m/search?keyfrom=dict.mindex&vendor=&q="
+ word;
wvResult.loadUrl(strUrl);
wvResult1.loadUrl(strUrl1);
wvResult2.loadUrl(strUrl2);
}
}
}
activity_main.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: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:layout_below="@id/etWord"
- android:layout_marginTop="10dip"
- android:id="@+id/wvSearchResult"
- android:layout_width="fill_parent"
- android:layout_height="120dip"
- android:layout_weight="1"
- />
- <WebView
- android:layout_below="@id/wvSearchResult"
- android:layout_marginTop="10dip"
- android:id="@+id/wvSearchResult1"
- android:layout_width="fill_parent"
- android:layout_height="120dip"
- android:layout_weight="1"
- />
- <WebView
- android:id="@+id/wvSearchResult2"
- android:layout_width="fill_parent"
- android:layout_height="120dip"
- android:layout_below="@id/wvSearchResult1"
- android:layout_marginTop="10dip"
- android:layout_weight="1" />
- </RelativeLayout>