词典

来源:互联网 发布:origin导入excel数据 编辑:程序博客网 时间:2024/04/27 13:26
  1. 1.布局文件   
  1. <EditText  
  2.         android:id="@+id/etWord"  
  3.         android:layout_width="wrap_content"  
  4.         android:layout_height="wrap_content"  
  5.         android:layout_alignParentLeft="true"  
  6.         android:layout_alignParentTop="true"  
  7.         android:layout_marginTop="27dp"  
  8.         android:background="@android:drawable/edit_text"  
  9.         android:ems="10"  
  10.         android:singleLine="true"  
  11.         android:textColor="#552006"  
  12.         android:textColorHint="#782f10" >  
  13.         <requestFocus />  
  14.     </EditText>  
  15.     <WebView  
  16.         android:id="@+id/wvSearchResult"  
  17.         android:layout_width="match_parent"  
  18.         android:layout_height="match_parent"  
  19.         android:layout_alignLeft="@+id/etWord"  
  20.         android:layout_below="@+id/etWord"  
  21.         android:layout_marginTop="22dp"  
  22.         android:background="@drawable/bg_roundcorner"  
  23.         android:textAppearance="?android:attr/textAppearanceMedium"  
  24.         android:textSize="25sp" />  
  25.   
  26.     <Button  
  27.         android:id="@+id/btnSearch"  
  28.         android:layout_width="wrap_content"  
  29.         android:layout_height="wrap_content"  
  30.         android:layout_above="@+id/wvSearchResult"  
  31.         android:layout_alignParentRight="true"  
  32.         android:background="@drawable/ibsearchword"  
  33.         android:onClick="searchWord" />  
  34.   
  35. </RelativeLayout>  

2.代码

  1. private void initViews() {  
  2.         etWord = (EditText) findViewById(R.id.etWord);  
  3.         wvResult = (WebView) findViewById(R.id.wvSearchResult);  
  4.         wvResult.setWebViewClient(new WebViewClient() {  
  5.             @Override  
  6.             public boolean shouldOverrideUrlLoading(WebView view, String url) {  
  7.                 view.loadUrl(url);  
  8.                 return true;  
  9.             }  
  10.         });  
  11.     }  
  12.   
  13.     @Override  
  14.     public boolean onCreateOptionsMenu(Menu menu) {  
  15.         getMenuInflater().inflate(R.menu.main, menu);  
  16.         return true;  
  17.     }  
  18.   
  19.     public void searchWord(View view) {  
  20.         String word = etWord.getText().toString();  
  21.         if (TextUtils.isEmpty(word)) {  
  22.             Toast.makeText(this, "查询内容不能为空!", Toast.LENGTH_LONG).show();  
  23.         } else {  
  24.   
  25.             final String strUrl = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&vendor=&q="  
  26.                     + word;  
  27.             wvResult.loadUrl(strUrl);  
  28.         }  
  29.     }  

0 0