EditText
EditText是可输入控件,同样继承自TextView,可以使用期所有属性和事件
🌲通过本例子,我们将制作一个简单的登录界面:
🚩步骤
我们先用模板新建一个EmptyActivity名为EditTextActivity用于存放登陆界面相关的功能及样式:
我们想要实现以下控件:
- 一个用户名输入框
- 一个密码输入框
- 一个登录按钮
🔨使用到的属性:
名称 | 解释 | 格式 |
---|---|---|
android:hint | 不输入时的提示信息 | 字符串 |
android:inputType | 输入文本格式 | number/textPassword/tex…t |
android:drawableLeft | 在控件内部左侧放置资源 | @drawable/XXX |
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EditTextActivity"
android:padding="15dp"
>
<EditText
android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textColor