Android 有道词典的简单实现方法介绍

沫了沫了夏

沫了沫了夏

2016-02-19 10:25

下面是个Android 有道词典的简单实现方法介绍教程,撑握了其技术要点,学起来就简单多了。赶紧跟着图老师小编一起来看看吧!

首先看程序界面如下!

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

1、布局文件:
代码如下:

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="查询" /

  Button
    android:id="@+id/btnclear"
    android:layout_width="60px"
    android:layout_height="40px"
    android:layout_x="230px"
    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

2、修改MainActivity:
代码如下:

public class MainActivity extends Activity {
 private Button btnSearch;
 private Button btnClear;
 private EditText editText;
 private WebView reswebView;

 private void SetView() {
  btnSearch = (Button) findViewById(R.id.btnsearch);
  btnClear = (Button) findViewById(R.id.btnclear);
  editText = (EditText) findViewById(R.id.editText);
  reswebView = (WebView) findViewById(R.id.reswebView);
  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);
    }
   }
  });
  btnClear.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    editText.setText("");
   }
  });
 }

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  SetView();
 }
}

3、在清单文件中添加网络访问权限:

uses-permission android:name="android.permission.INTERNET" /

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

运行程序即可!

展开更多 50%)
分享

猜你喜欢

Android 有道词典的简单实现方法介绍

编程语言 网络编程
Android 有道词典的简单实现方法介绍

有道词典怎么屏幕取词 有道词典屏幕取词方法

软件教程
有道词典怎么屏幕取词 有道词典屏幕取词方法

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

有道词典怎么翻译?

电脑网络
有道词典怎么翻译?

有道词典设置卡片自动发音方法

手机软件 应用软件
有道词典设置卡片自动发音方法

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

有道词典如何发贴

手机软件 应用软件
有道词典如何发贴

有道词典怎么离线翻译

手机软件 应用软件
有道词典怎么离线翻译

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

如何在任务栏通知区操作打开Windows7的回收站

如何在任务栏通知区操作打开Windows7的回收站

SQL Server导入、导出、备份数据方法

SQL Server导入、导出、备份数据方法
下拉加载更多内容 ↓