Android 有道詞典的簡(jiǎn)單實(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(), "請(qǐng)輸入查詢字符", 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開發(fā)中類加載器DexClassLoader的簡(jiǎn)單使用講解
這篇文章主要介紹了Android開發(fā)中類加載器DexClassLoader的簡(jiǎn)單使用講解,DexClassLoader可以看作是一個(gè)特殊的Java中的ClassLoader,需要的朋友可以參考下2016-04-04分享一個(gè)輕量級(jí)圖片加載類 ImageLoader
這篇文章給大家分享一個(gè)輕量級(jí)圖片加載類 ImageLoader,需要的朋友可以參考下2016-08-08Android中關(guān)于百度糯米app關(guān)閉網(wǎng)頁(yè)或窗口的方法(99%人不知)
這篇文章主要介紹了Android中關(guān)于百度糯米app中關(guān)閉網(wǎng)頁(yè)或窗口的方法,其實(shí)解決方法到很簡(jiǎn)單,但是很多人都不知道如何解決的,在網(wǎng)上也很難找到答案的,下面小編給大家揭曉答案,需要的朋友可以參考下2016-08-08Android實(shí)現(xiàn)拍照添加時(shí)間水印
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)拍照添加時(shí)間水印,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03Android實(shí)現(xiàn)瘋狂連連看游戲之開發(fā)游戲界面(二)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)瘋狂連連看游戲之開發(fā)游戲界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03Android實(shí)現(xiàn)從底部彈出的Dialog的實(shí)例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)從底部彈出的Dialog的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值 ,需要的朋友可以參考下2018-04-04Android仿高德首頁(yè)三段式滑動(dòng)效果的示例代碼
很多app都會(huì)使用三段式滑動(dòng),比如說高德的首頁(yè)和某寶等物流信息都是使用的三段式滑動(dòng)方式。本文將介紹如何實(shí)現(xiàn)這一效果,感興趣的可以學(xué)習(xí)一下2022-01-01簡(jiǎn)單實(shí)用的Android studio 調(diào)試技巧
這篇文章主要介紹了簡(jiǎn)單實(shí)用的Android studio 調(diào)試技巧的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07Android 布局控件之LinearLayout詳細(xì)介紹
Android 布局控件之LinearLayout詳細(xì)介紹,需要的朋友可以參考一下2013-05-05