有道词典的查询

来源:互联网 发布:淘宝里什么是历史宝贝 编辑:程序博客网 时间:2024/05/02 07:51

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="
http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    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" >

    <EditText
        android:id="@+id/edt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/btn"
        android:layout_alignBottom="@+id/btn"
        android:layout_alignParentLeft="true"
        android:ems="10" >

        <requestFocus />
    </EditText>
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:onClick="findWord"
        android:layout_marginTop="58dp"
        android:text="查询" />
   
   <WebView android:id="@+id/wvSearchResult"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_alignLeft="@+id/edt"
     android:layout_below="@+id/edt"
     android:layout_marginTop="22dp"  
     android:textSize="25sp"
     >
    
 </WebView>
    

</RelativeLayout>

 

package com.example.youdao;


import org.w3c.dom.Text;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
   
private Button myButton01;
private EditText mEditText;
private WebView mWebView1;
    
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  initView();
 }

 private void initView() {
  // TODO Auto-generated method stub
  myButton01=(Button) findViewById(R.id.btn);   
     mEditText=(EditText) findViewById(R.id.edt);
     mWebView1=(WebView)findViewById(R.id.wvSearchResult);
 }

     public void findWord(View view) {
   String strText=(mEditText.getText().toString()).trim(); //除去字符串开头和末尾的空格或其他字符
   if (strText.length()==0) {  //判断查找单词是否为空
    Toast.makeText(MainActivity.this, "查询内容不能为空!", Toast.LENGTH_LONG).show();
   }
   else{
    String strURL="
http://dict.youdao.com/m/search?keyfrom=dict.mindex&q="+strText;//加载路径
    mWebView1.loadUrl(strURL) ;//监听webview的通知,加载到WebView控件上显示
    mWebView1.setWebViewClient(new WebViewClient() { //禁止调用系统浏览器
        public boolean shouldOverrideUrlLoading(WebView view, String url){
            view.loadUrl(url);
            return false;
        }
    });
    
   }
  }
 }

 

 

 

0 0
原创粉丝点击