WebView調用有道詞典實如今線查詞

來源:互聯網
上載者:User

標籤:abs   推斷   rom   center   schema   roi   調用   pre   ==   

    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方法,效果:



WebView調用有道詞典實如今線查詞

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.