首页 > 其他分享 >Android应用实例(一)之---有道辞典VZ.0

Android应用实例(一)之---有道辞典VZ.0

时间:2023-02-28 11:33:59浏览次数:36  
标签:layout VZ.0 Button id --- WebView import Android android


大家好,这是我做的一个简单的有道Android的DEMO,只是简单的雏形。界面设计也有点丑陋呵呵~ 看看下


第一步:思路解析

从界面看一共用了三个控件EditText,Button,WebView。其实是四个,是当我们查询内容为空的时候用来提示的Toast控件。

我们在EditText输入查询内容,这里包括中文,英文。然后通过参数的形式,从https://dict.youdao.com/m取出数据把结果

存放在WebView里。

第二步:入手程序。

首先是布局界面main.xml

<?xml versinotallow="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="https://schemas.android.com/apk/res/android"
android:orientatinotallow="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 建立一個EditText -->
<EditText
android:id="@+id/myEditText1"
android:layout_width="200px"
android:layout_height="40px"
android:textSize="18sp"
android:layout_x="5px"
android:layout_y="32px"
/>
<!-- 建立一個Button -->
<Button
android:id="@+id/myButton01"
android:layout_width="60px"
android:layout_height="40px"
android:text="查询"
android:layout_x="205px"
android:layout_y="35px"
/>
<Button
android:id="@+id/myButton02"
android:layout_height="40px"
android:layout_width="50px"
android:text="清空"
android:layout_y="35px"
android:layout_x="270px"
/>
<!-- 建立一個WebView -->
<WebView
android:id="@+id/myWebView1"
android:layout_height="330px"
android:layout_width="300px"
android:layout_x="7px"
android:layout_y="90px"
android:background="@drawable/black"
android:focusable="false"
/>
</AbsoluteLayout>
其次是主类YouDao.java
package AndroidApplication.Instance;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class YouDao extends Activity
{
//查询按钮申明
private Button myButton01;
//清空按钮申明
private Button myButton02;
//输入框申明
private EditText mEditText1;
//加载数据的WebView申明
private WebView mWebView1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获得布局的几个控件
myButton01 = (Button)findViewById(R.id.myButton01);
myButton02 = (Button) findViewById(R.id.myButton02);
mEditText1 = (EditText) findViewById(R.id.myEditText1);
mWebView1 = (WebView) findViewById(R.id.myWebView1);
//查询按钮添加事件
myButton01.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View arg0)
{
String strURI = (mEditText1.getText().toString());
strURI = strURI.trim();
//如果查询内容为空提示
if (strURI.length() == 0)
{
Toast.makeText(YouDao.this, "查询内容不能为空!", Toast.LENGTH_LONG)
.show();
}
//否则则以参数的形式从https://dict.youdao.com/m取得数据,加载到WebView里.
else
{
String strURL = "https://dict.youdao.com/m/search?keyfrom=dict.mindex&q="
+ strURI;
mWebView1.loadUrl(strURL);
}
}
});
//清空按钮添加事件,将EditText置空
myButton02.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
mEditText1.setText("");
}
});
}
}

程序大功告成。其实大家会发现,这个应用相当简单,只是你们没有想到而已,Narcissism一下呵呵~。如果大家程序跑不起来

,可以Q我Email我,在留言里留下你们的Q或者Email.

今天就到此为止! 谢谢大家~

标签:layout,VZ.0,Button,id,---,WebView,import,Android,android
From: https://blog.51cto.com/u_15070324/6090627

相关文章

  • k8s 部署 metrics-server
    k8s提供了top命令可用于统计资源使用情况,它包含有node和pod两个⼦命令,分别显⽰node节点和Pod对象的资源使⽤信息。kubectltop命令依赖于metrics接口。k8s系......
  • idea2020.1打不开和运行nbcio-boot错误解决方案出现下面的问题
    今天应用户要求进行ideal的项目运行测试出现下面的问题  按照上面提示,把原来jetbrains-agent.jar文件修改成上面文件,同时目录也按上面要求建立之后运行成功了。后来编译运......
  • 关于Android中Spinner的使用
    这是一个关于使用Android中Spinner控件的方法,一个简单的代码及测试效果如下:1、主程序packageext.owen.testSpinner;importandroid.app.Activity;importandroid.os.Bund......
  • Android高手进阶教程(十五)之---通过Location获取Address的使用!
    大家好,上一节我讲了一下如何通过LocationManager来获取Location,没有看过上一节的同学,可以点击如下链接返回查看:​​Android高手进阶教程十四之---AndroidLocation的使用!​......
  • android AsyncTask入门
    要使用这个东西,要newAsyncTask.此时相当与启动个新线程.你需要重载doInbackground这个东西相当与run方法。开始执行后台操作.操作完了后onPostExecute这个函数更新......
  • Android 反编译资料整理
    Madeby李文栋2010-12-13 Monday于北京一、反编译流程图​​​​二、工具使用方法(命令)准备工作假设我的工作目录为$AndroidDecompile,首先要将system.img中(或......
  • C# 货币金额中文(英文)大写转换方法-工具类
    1publicstaticclassMoney{2privatestaticreadonlyStringcnNumber="零壹贰叁肆伍陆柒捌玖";3privatestaticreadonlyStringcnUni......
  • 基于QT实现的影院票务系统[2023-02-28]
    基于QT实现的影院票务系统[2023-02-28]基于QT实现的影院票务系统影院票务系统1.系统权限管理系统分3种用户权限:A游客权限-注册会员,查看电影场次信息,购买电影票B会......
  • shell-awk-打印进程ID
    dockerps|grepcita|awk-F""'{print$1}'awk-F""按空格分割e.g.[root@host-10-0-169-67~]#sudodockerpsCONTAINERIDIMAGE......
  • LeetCode算法训练-回溯 491.递增子序列 46.全排列 47.全排列 II
    欢迎关注个人公众号:爱喝可可牛奶LeetCode算法训练-回溯491.递增子序列46.全排列47.全排列IILeetCode491.递增子序列分析找出并返回所有数组中不同的递增子序列......