標籤: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調用有道詞典實如今線查詞