Android实例之有道词典
来源:互联网 发布:歪歪是什么软件 编辑:程序博客网 时间:2024/04/28 21:18
运行效果图展示:
布局文件activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/RelativeLayout1" 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" ><EditText android:id="@+id/edit_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:maxLength="30" android:hint="输入你要查询的内容"/><Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/edit_text" android:layout_below="@+id/edit_text" android:text="查询" /><WebView android:id="@+id/wvSearchResult" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/button1" android:layout_centerHorizontal="true" android:layout_marginTop="15dp" android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="22sp" /></RelativeLayout>
MainActivity.java文件代码展示:
package com.example.dictonion;import android.os.Bundle;import android.app.Activity;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 Button myButton01; private EditText mEditText1; private WebView mWebView1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myButton01 = (Button)findViewById(R.id.button1); mEditText1 = (EditText) findViewById(R.id.edit_text); mWebView1 = (WebView) findViewById(R.id.wvSearchResult); myButton01.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String strURI = (mEditText1.getText().toString()); strURI = strURI.trim(); if (strURI.length() == 0) { Toast.makeText(MainActivity.this, "查询内容不能为空!", Toast.LENGTH_LONG) .show(); } else { String strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q=" + strURI; mWebView1.loadUrl(strURL); } } }); } @Override public 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; }}
项目权限:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.dictonion" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.dictonion.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
运行结果:
0 0
- Android实例之有道词典
- Android应用实例-有道词典
- Android应用实例---有道词典
- Android基础-实现有道词典实例
- android学习-有道词典开发实例
- Android进阶2之有道词典开发
- android中的有道词典
- Android有道词典开发
- Android模拟有道词典
- Android应用有道词典
- Android模拟有道词典
- Android实现有道词典
- Android-webview加载有道词典
- android有道词典简单开发
- Android应用实例之有道辞典
- ******Android应用实例之有道辞典(WebView) **********
- Android应用实例之有道辞典
- Android应用实例之有道辞典(WebView)
- grep用法
- oracle数据库笔记0
- 4.19
- Office Tab Center
- JVM调优系列:(五)JVM常用调试参数和工具
- Android实例之有道词典
- 腾讯实习经验
- LintCode 寻找缺失的数
- 2015年换工作感想
- 从其他程序员身上学习,取长补短
- 黑马day11 c3p0数据库连接池
- 排序算法之归并排序Java版
- 构造函数和析构函数的小问题
- Gensim官方介绍翻译