最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android組件WebView編寫有道詞典小案例分享

 更新時(shí)間:2016年05月26日 15:45:23   作者:GXSeveryday  
這篇文章主要為大家分享了Android組件WebView編寫有道詞典小案例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近學(xué)習(xí)了WebView組件,寫了一個(gè)有道詞典的小案例,分享給大家,供大家參考,具體內(nèi)容如下
效果圖

源碼下載https://coding.net/u/gxs1225/p/YouDaoDictionary/git

代碼如下:
布局

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/mainbg"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context=".MainActivity" >
 <EditText
  android:id="@+id/etWord"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentLeft="true"
  android:layout_alignParentTop="true"
  android:layout_marginTop="27dp"
  android:background="@android:drawable/edit_text"
  android:ems="10"
  android:singleLine="true"
  android:textColor="#552006"
  android:textColorHint="#782f10" >
  <requestFocus />
 </EditText>
 <WebView
  android:id="@+id/wvSearchResult"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_alignLeft="@+id/etWord"
  android:layout_below="@+id/etWord"
  android:layout_marginTop="22dp"
  android:background="@drawable/bg_roundcorner"
  android:textAppearance="?android:attr/textAppearanceMedium"
  android:textSize="25sp" />

 <Button
  android:id="@+id/btnSearch"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_above="@+id/wvSearchResult"
  android:layout_alignParentRight="true"
  android:background="@drawable/ibsearchword"
  android:onClick="searchWord" />

</RelativeLayout>

MainActivity.java

package com.example.youdaodictionary;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
 private EditText etWord;
 private WebView wvResult;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  initViews();
 }

 private void initViews() {
  etWord = (EditText) findViewById(R.id.etWord);
  wvResult = (WebView) findViewById(R.id.wvSearchResult);
  wvResult.setWebViewClient(new WebViewClient() {
   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
   }
  });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }

 public void searchWord(View view) {
  String word = etWord.getText().toString();
  if (TextUtils.isEmpty(word)) {
   Toast.makeText(this, "查詢內(nèi)容不能為空!", Toast.LENGTH_LONG).show();
  } else {

   final String strUrl = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&vendor=&q="
     + word;
   wvResult.loadUrl(strUrl);
  }
 }
}

更多精彩內(nèi)容大家可以參考專題進(jìn)行學(xué)習(xí):《Android組件WebView使用案例匯總》

以上就是本文的全部內(nèi)容,希望對(duì)大家學(xué)習(xí)Android軟件編程有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

吴忠市| 靖江市| 天长市| 西吉县| 开阳县| 伊宁县| 四子王旗| 鸡泽县| 白水县| 曲沃县| 塔河县| 桐乡市| 凭祥市| 泗水县| 隆尧县| 岳普湖县| 塔河县| 水富县| 大邑县| 昌邑市| 宿迁市| 云林县| 宜春市| 苏尼特右旗| 明溪县| 抚顺县| 遂溪县| 宝清县| 雷波县| 收藏| 逊克县| 巩义市| 景东| 祁东县| 汉沽区| 凤城市| 娱乐| 文登市| 松滋市| 弋阳县| 赤峰市|