调用有道词典查词
来源:互联网 发布:美妆软件哪个好 编辑:程序博客网 时间:2024/05/01 10:22
1,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/main_bg" 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/et_word" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="20dp" android:background="@android:drawable/edit_text" android:ems="10" android:singleLine="true" android:textColor="#552006" android:textColorHint="#782f10" > <requestFocus /> </EditText> <Button android:id="@+id/btnSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" android:layout_toRightOf="@id/et_word" android:layout_alignTop="@id/et_word" android:layout_marginLeft="5dp" /> <WebView android:id="@+id/wvSearchResult" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignLeft="@+id/etWord" android:layout_below="@+id/et_word" android:layout_marginTop="22dp" android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="25sp" /></RelativeLayout>12,MainActivity代码public class MainActivity extends Activity { private EditText ed_word =null; private Button search =null; private WebView web =null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); search.setOnClickListener(new OnClickListener() { String strURL; @Override public void onClick(View v) { // TODO Auto-generated method stub String str_word =ed_word.getText().toString(); if(str_word!=null){ str_word =str_word.trim(); //去除一下空格 strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q=" + str_word; //组成请求的url //加载网页 web.loadUrl(strURL); web.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub view.loadUrl(url);//不跳到系统浏览器 return true; } }); //进度条 web.setWebChromeClient(new WebChromeClient(){ public void onProgressChanged(WebView view, int newProgress) { MainActivity.this.setProgress(newProgress*100);//设置进度条 }; }); }else { Toast.makeText(MainActivity.this,"单词不能为空!" , 3000); } } }); } private void initView() { // TODO Auto-generated method stub ed_word =(EditText)findViewById(R.id.et_word); search =(Button) findViewById(R.id.btnSearch); web =(WebView)findViewById(R.id.wvSearchResult); } }1加入访问网络的权限:<uses-permission android:name="android.permission.INTERNET"/>![这里写图片![这里写图片描述](http://img.blog.csdn.net/20150703151157397)描述](http://img.blog.csdn.net/20150703150639768)
这里写图片描述
0 0
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- 调用有道词典查词
- WebView调用有道词典实现在线查词
- android :调用有道词典查字词
- 调用有道词典查询
- 调用有道辞典查词
- linux下借助有道在线词典查词
- 如何中断一个正在运行的线程
- leetcode | Minimum Depth of Binary Tree
- NSOperationQueue和GCD的区别,以及在什么场合下使用
- 校验码
- 有道词典
- 调用有道词典查词
- 安装打印机时出现"无法安装,打印处理器不存在"
- 最大子向量和(连续子数组的最大和_1372
- 手游接入Facebook的那些坑
- 解读HTTP的META标签
- 无法定位序数 xxxx 与动态链接库 avcodec-55.dll上
- 日志文件logback
- Google 镜像站搜集
- RocketMQ 环境搭建