WebView调用有道词典实现在线查词

    WebView(网络视图)能加载显示网页,可以将其视为一个浏览器。它使用了WebKit渲染引擎加载显示网页,使用方法很简单,直接在XML文件中写入webview控件即可,主要代码如下:

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <EditText
    android:id="@+id/editText"
    android:layout_width="150px"
    android:layout_height="40px"
    android:layout_x="5px"
    android:layout_y="32px"
    android:textSize="18sp" />
  <Button
    android:id="@+id/btnsearch"
    android:layout_width="60px"
    android:layout_height="40px"
    android:layout_x="165px"
    android:layout_y="35px"
    android:text="查看" />
  <WebView
    android:id="@+id/reswebView"
    android:layout_width="300px"
    android:layout_height="330px"
    android:layout_x="7px"
    android:layout_y="90px"
    android:focusable="false" />
</AbsoluteLayout>

程序执行顺序为,先取到edittext控件的内容,判断内容是否为空,不为空则提交到WebView中。

代码如下:

btnSearch = (Button) findViewById(R.id.btnsearch);
btnSearch.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    String strUri = editText.getText().toString();
    strUri = strUri.trim();
    if (strUri.length() == 0) {
     Toast.makeText(getApplicationContext(), "请输入查询字符", 1).show();
    } else {
     String strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q=" + strUri;
     reswebView.loadUrl(strURL);
    }
   }
});

主要就是调用webview的loadUrl方法,效果截图:

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-29 09:25:19

WebView调用有道词典实现在线查词的相关文章

WebView调用有道词典实如今线查词

    WebView(网络视图)能载入显示网页,能够将其视为一个浏览器.它使用了WebKit渲染引擎载入显示网页,用法非常easy,直接在XML文件里写入webview控件就可以,主要代码例如以下: <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_heigh

调用有道词典查词

调用有道词典 DbHelper类进行数据操作,activity_mian.xml布局页面,MainAvtivity类实现继承与查询等操作. MainAvtivity.java: 1 package com.example.happydictionary; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.text.TextUtils; 6 import android.view.Menu;

android/java调用有道词典

之前学的时候碰了两壁:1.android4.0以上不能在主线程使用网络,2.不能在线程更新UI状态 因为网上很多给出的代码都有这两个隐患,所以很多人都调用不成功.明白了这两点下面就好办了. PS:代码非原创,由网络上android4.0以下的低版本代码改进而来,适用于android4.0以上,当然之前的应该也适用 直接上demo---translate http://pan.baidu.com/s/1gdIK4QR android/java调用有道词典

ubuntu下python脚本调用有道词典API实现命令行查词

#!/usr/bin/env python #coding=utf-8 '''   python使用有道词典的API来实现命令行查词 ''' import urllib2 import json import sys  reload(sys) sys.setdefaultencoding('utf-8') key = '1096888977' keyfrom = 'bloketest' doctype = 'json' u = 'http://fanyi.youdao.com/openapi.d

调用有道词典查询单词

package com.example.happydictionary; import android.app.Activity; import android.os.Bundle; import android.text.TextUtils; import android.view.Menu; import android.view.View; import android.widget.EditText; import android.widget.TextView; import com.

Python爬虫实践 —— 3.利用爬虫提取返回值,模拟有道词典接口

有道词典的web接口,实际上可以用爬虫模拟,输入key,拼接为有道词典接口的formdata,爬取返回值,实际为Ajax动态生成的translation,这样外部来看实现了翻译接口的模拟,相当于爬虫模拟浏览器调用了有道词典web接口,其实讲真的话来说,直接调用有道web接口,传json参数就可以了,不用这么费事,但爬虫模拟了人登陆web,输入关键词,获得翻译结果的过程. 浏览器输入操作,解析有道词典翻译的web接口url和格式 #爬虫模拟调用有道词典web接口调用 from urllib imp

调用网易有道词典api

# -*- coding: utf-8 -*- #python 27 #xiaodeng #调用网易有道词典api import urllib import json class Youdao(): def __init__(self,word): self.url='http://fanyi.youdao.com/openapi.do' #url.key.keyfrom都是固定的值,所以采用这种方式赋值 self.key='929705525' self.keyfrom='pythonxiao

Java和Python使用有道词典制作查单词脚本

Java和Python使用有道词典制作查单词脚本 先上两张图看一下效果 Java的: Python的: 今天突发奇想,想做个查单词的东西,就赶紧去有道词典官网看了一下,原来我们要查询的单词是嵌入在网页地址中送给有道词典的,然后页面的结果就是我们需要的单词释义,所以这个东西需要的技术知识只有: 正则表达式 我们要做的只是从获取到的网页源码中提取处单词释义,所以这里只说提取单词释义的正则表达式. 分析网页源码,我们可以看到,单词释义都在一个div标签内,如图: 首要目标是获取这一部分,正则表达式可以

有道词典Demo(WebView)

学习了WebView组件,写了一个有道词典的小案例 效果图如下: 源码下载地址:https://coding.net/u/gxs1225/p/YouDaoDictionary/git 代码如下: 布局 activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/too