Android 有道詞典的簡單實(shí)現(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" />
運(yùn)行程序即可!
相關(guān)文章
android studio 一直卡在Gradle:Build Running的幾種解決辦法
這篇文章主要介紹了android studio 一直卡在Gradle:Build Running的解決辦法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-10-10
詳解Android創(chuàng)建Handler的必備知識(shí)點(diǎn)
本篇文章主要介紹Handler中需要了解的幾個(gè)必備知識(shí)點(diǎn),比如Handler創(chuàng)建、異步Handler是個(gè)啥及如何創(chuàng)建,感興趣的小伙伴快跟隨小編一起學(xué)習(xí)一下2022-10-10
Android沉浸式狀態(tài)欄設(shè)計(jì)的實(shí)例代碼
本篇文章主要介紹了Android沉浸式狀態(tài)欄設(shè)計(jì)的實(shí)例代碼,整理了詳細(xì)的代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Android FaceDetector實(shí)現(xiàn)人臉檢測功能
這篇文章主要為大家詳細(xì)介紹了Android FaceDetector實(shí)現(xiàn)人臉檢測功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android使用OkHttp進(jìn)行網(wǎng)絡(luò)同步異步操作
這篇文章主要為大家詳細(xì)介紹了Android使用OkHttp進(jìn)行網(wǎng)絡(luò)同步異步操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07
Android listview數(shù)據(jù)顯示及提示信息的實(shí)例
這篇文章主要介紹了Android listview數(shù)據(jù)顯示及提示信息的實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android編程中File文件常見存儲(chǔ)與讀取操作demo示例
這篇文章主要介紹了Android編程中File文件常見存儲(chǔ)與讀取操作,結(jié)合實(shí)例形式分析了Android針對文件的打開、讀寫及布局等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09

