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

    WebView(网络视图)能载入显示网页,能够将其视为一个浏览器。它使用了WebKit渲染引擎载入显示网页,用法非常easy,直接在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方法,效果截图:



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值