Android 有道詞典的簡單實現(xiàn)方法介紹
首先看程序界面如下!

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、在清單文件中添加網(wǎng)絡(luò)訪問權(quán)限:
<uses-permission android:name="android.permission.INTERNET" />
運行程序即可!
相關(guān)文章
Android開發(fā)中類加載器DexClassLoader的簡單使用講解
這篇文章主要介紹了Android開發(fā)中類加載器DexClassLoader的簡單使用講解,DexClassLoader可以看作是一個特殊的Java中的ClassLoader,需要的朋友可以參考下2016-04-04
Android中關(guān)于百度糯米app關(guān)閉網(wǎng)頁或窗口的方法(99%人不知)
這篇文章主要介紹了Android中關(guān)于百度糯米app中關(guān)閉網(wǎng)頁或窗口的方法,其實解決方法到很簡單,但是很多人都不知道如何解決的,在網(wǎng)上也很難找到答案的,下面小編給大家揭曉答案,需要的朋友可以參考下2016-08-08
Android實現(xiàn)瘋狂連連看游戲之開發(fā)游戲界面(二)
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)瘋狂連連看游戲之開發(fā)游戲界面,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03
Android實現(xiàn)從底部彈出的Dialog的實例代碼
這篇文章主要介紹了Android實現(xiàn)從底部彈出的Dialog的實例代碼,非常不錯,具有參考借鑒價值 ,需要的朋友可以參考下2018-04-04
簡單實用的Android studio 調(diào)試技巧
這篇文章主要介紹了簡單實用的Android studio 調(diào)試技巧的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07
Android 布局控件之LinearLayout詳細(xì)介紹
Android 布局控件之LinearLayout詳細(xì)介紹,需要的朋友可以參考一下2013-05-05

