练习:WebView控件使用(链接有道词典查单词)
来源:互联网 发布:linux如何解压zip文件 编辑:程序博客网 时间:2024/04/29 20:59
一。练习结果
1.在editorText输入英语单词,点击查询,下方webView控件显示有道词典中的翻译。
2.结果图片:
二:分析
与其他的控件一样,WebView(网络视图)能加载显示网页,可以将其视为一个浏览器。它使用了WebKit渲染引擎加载显示网页。
三:代码
MainActivity:
package com.example.yd_webview;import android.os.Bundle;import android.app.Activity;import android.text.style.ClickableSpan;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.webkit.WebView;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity {//声明控件private EditText edt_select;private Button btn_select;private Button btn_clern;private WebView webView_select;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);getViews();//清空btn_clern.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubedt_select.setText("");}});//查询btn_select.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubString strURI=edt_select.getText().toString();strURI=strURI.trim();//如果内容为空if(strURI.length()==0){Toast.makeText(MainActivity.this, "查询内容不能为空", Toast.LENGTH_LONG).show();}else{String strURL="http://dict.youdao.com/search?q="+strURI;webView_select.loadUrl(strURL);}}});}/*获取控件*/public void getViews(){edt_select=(EditText) findViewById(R.id.edt_select);btn_select=(Button) findViewById(R.id.btn_select);btn_clern=(Button) findViewById(R.id.btn_clern);webView_select=(WebView) findViewById(R.id.webView_select);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" 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" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/edt_select" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:maxLines="1" > </EditText> <Button android:id="@+id/btn_select" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查询" /> <Button android:id="@+id/btn_clern" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="清空" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <WebView android:id="@+id/webView_select" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout></LinearLayout>AndroidMainfest.xml中添加联网权限:
<uses-permission android:name="android.permission.INTERNET"/>
四:相关下载
http://download.csdn.net/download/yyd_diablo/8833173
0 0
- 练习:WebView控件使用(链接有道词典查单词)
- Java和Python使用有道词典制作查单词脚本
- 使用android的webview控件访问有道词典的url
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- WebView实现有道词典
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典-WebView
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- 有道词典Demo(WebView)
- mac/linux环境下调试tomcat端口被占用问题
- LoadRunner的下载、安装以及破解
- 卷积理解
- java/lang/NoClassDefFoundError: java/lang/invoke/MethodHandle的解决办法
- WWW
- 练习:WebView控件使用(链接有道词典查单词)
- 加载网络图片中,给ImageView增加提示文字
- SQLite可视化管理工具汇总
- 多核平台下的JAVA优化
- HDU 1087(Super Jumping! Jumping! Jumping!)不降子序列和最大
- 共享打印机出现spoolsv.exe应用程序错误的另类解法
- VC6.0 error LNK2001: unresolved external symbol _main解决办法
- C#中计算时间差
- 机器学习与数据挖掘1