看看

MainActivity.java

[java]  view plain copy print ?
  1. package com.example.youdaodictionary;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.text.TextUtils;  
  6. import android.view.Menu;  
  7. import android.view.View;  
  8. import android.webkit.WebView;  
  9. import android.webkit.WebViewClient;  
  10. import android.widget.EditText;  
  11. import android.widget.Toast;  
  12.   
  13. public class MainActivity extends Activity {  
  14.     private EditText etWord;  
  15.     private WebView wvResult;  
  16.   
  17.       
  18.   
  19.     @Override  
  20.     protected void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.         setContentView(R.layout.activity_main);  
  23.   
  24.         initViews();  
  25.           
  26.     }  
  27.   
  28.     private void initViews() {  
  29.         etWord = (EditText) findViewById(R.id.etWord);  
  30.         wvResult = (WebView) findViewById(R.id.wvSearchResult);  
  31.         wvResult.setWebViewClient(new WebViewClient() {  
  32.             @Override  
  33.             public boolean shouldOverrideUrlLoading(WebView view, String url) {  
  34.                 view.loadUrl(url);  
  35.                 return true;  
  36.             }  
  37.         });  
  38.     }  
  39.       
  40.       
  41.       
  42.       
  43.   
  44.     @Override  
  45.     public boolean onCreateOptionsMenu(Menu menu) {  
  46.         getMenuInflater().inflate(R.menu.main, menu);  
  47.         return true;  
  48.     }  
  49.   
  50.     public void searchWord(View view) {  
  51.         String word = etWord.getText().toString();  
  52.         if (TextUtils.isEmpty(word)) {  
  53.             Toast.makeText(this"查询内容不能为空!", Toast.LENGTH_LONG).show();  
  54.         } else {  
  55.   
  56.             final String strUrl = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&vendor=&q="  
  57.                     + word;  
  58.               
  59.               
  60.               
  61.               
  62.             wvResult.loadUrl(strUrl);  
  63.               
  64.         }  
  65.     }  
  66.       
  67.       
  68.       
  69. }  

activity_main.xml

[html]  view plain copy print ?
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="wrap_content"  
  4.     android:layout_height="wrap_content"  
  5.     android:background="@drawable/bj"  
  6.     android:paddingBottom="@dimen/activity_vertical_margin"  
  7.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  8.     android:paddingRight="@dimen/activity_horizontal_margin"  
  9.     android:paddingTop="@dimen/activity_vertical_margin"  
  10.     tools:context=".MainActivity" >  
  11.   
  12.     <Button  
  13.         android:id="@+id/btnSearch"  
  14.         android:layout_toRightOf="@+id/etWord"   
  15.         android:layout_marginLeft="10dip"  
  16.         android:layout_width="fill_parent"  
  17.         android:layout_height="45dip"  
  18.         android:layout_weight="1"  
  19.         android:background="@drawable/an"  
  20.         android:onClick="searchWord" />  
  21.   
  22.     <EditText  
  23.         android:id="@+id/etWord"  
  24.         android:layout_width="wrap_content"  
  25.         android:layout_height="wrap_content"  
  26.         android:layout_weight="2"  
  27.         android:background="@android:drawable/edit_text"  
  28.         android:ems="10"  
  29.         android:singleLine="true"  
  30.         android:textColor="#552006"  
  31.         android:textColorHint="#782f10" />  
  32.   
  33.     <WebView  
  34.         android:id="@+id/wvSearchResult"  
  35.         android:layout_width="fill_parent"  
  36.         android:layout_height="120dip"  
  37.         android:layout_alignParentBottom="true"  
  38.         android:layout_below="@id/etWord"  
  39.         android:layout_marginTop="10dip"  
  40.         android:layout_weight="1" />  
  41.   
  42. </RelativeLayout>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值