今天要给大家介绍的是简单的编辑文本框;

先看一下它的基本属性:

1.Activity

public class EditTextActivity extends Activity {

    private EditText nameEditText;
private EditText passwordEditText;
private EditText ageEditText;
private Button button;
//编辑文本
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_text); nameEditText = (EditText)findViewById(R.id.nameEditTextId);
passwordEditText = (EditText)findViewById(R.id.passwordEditTextId);
ageEditText = (EditText)findViewById(R.id.ageEditTextId);
button = (Button)findViewById(R.id.buttonId); button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//获取你输入的姓名,密码,年龄
String name = nameEditText.getText().toString().trim();
String password = passwordEditText.getText().toString().trim();
String ageString = ageEditText.getText().toString().trim();
//用于提示消息
Toast.makeText(EditTextActivity.this, "name="+name+"\r\npassword="+password+
"\r\nage="+ageString, Toast.LENGTH_LONG).show();
}
}); }
}

2.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<!-- 文本编辑 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp" > <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="姓名:"
android:textSize="20sp" /> <EditText
android:id="@+id/nameEditTextId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入姓名" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="密码:"
android:textSize="20sp" /> <EditText
android:id="@+id/passwordEditTextId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:inputType="textPassword" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="年龄:"
android:textSize="20sp" /> <EditText
android:id="@+id/ageEditTextId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入年龄"
android:inputType="number"
android:maxLength="3" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="不可编辑"
android:textSize="20sp" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:hint="这里的内容不可以被更改" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="不可获取焦点(也不可以编辑)"
android:textSize="20sp" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="这个输入框获取不到焦点" /> <Button
android:id="@+id/buttonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示用户所填写的信息" /> </LinearLayout>

3.效果图如下:

最新文章

  1. [干货来袭]MSSQL Server on Linux预览版安装教程(先帮大家踩坑)
  2. iOS 汉字的拼音
  3. ContentProvider详解
  4. [工具开发] keepalived使用nagios监控脚本
  5. python 把数据 json格式输出
  6. C++ 编程输入输出语句
  7. FC网络学习笔记02 -网络配置方法
  8. lambda语法
  9. ArrayList实现根据某属性大小相间排序
  10. k64 datasheet学习笔记25--Multipurpose Clock Generator (MCG)
  11. PHP常用工具类
  12. svg常见形状
  13. WCF Restful Service Get / Post请求
  14. intent-filter 之 data 「scheme, host, port, mimeType, path, pathPrefix, pathPattern」
  15. leetCoder-wordBreak判断能否分词
  16. DotNetCore依赖注入实现批量注入
  17. CDN工作过程(第二种版本)
  18. 07_Java基础语法_第7天(练习)_讲义
  19. 简单记录一下ruby 循环
  20. vue相关理论知识

热门文章

  1. 并发编程&gt;&gt;并发级别(二)
  2. [Alpha]Scrum Meeting#9
  3. order by中用子查询排序
  4. CF1007D. Ants(树链剖分+线段树+2-SAT及前缀优化建图)
  5. Java Web入门学习(一) STS与Tomcat配置
  6. hibernate_Session接口_load_get
  7. OAuth机制原理(开放授权机制)
  8. WPF通过&lt;x:Array&gt;直接为ListBox的ItemsSource赋值
  9. 使用 Python 编写脚本并发布
  10. [转载]Vue 2.x 实战之后台管理系统开发(一)