EditView组件的使用
创建一个EditView组件:在main.xml中创建
<EditText
android:hint="EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLength="11"
android:singleLine="true"
android:inputType="phone"
android:background="@drawable/shape"
/>
android:hint="XXXX" 表示在文本框的后面出现背景文字
android:maxLength="" 表示文本框可输入的最大长度
android:singleLine="" 表示当前文本框所显示的的文字是否在同一行,属性值为true和false
android:inputType="" 表示当前文本框所输入文字的类型,可以是number phone等
android:background="" 调用一个.xml文件来进行设置文本框,上面的例子表示调用的是shape.xml文件
Shape.xml文件代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充颜色 -->
<solid android:color="#ffffff"/>
<!-- 设置四个角为弧形 -->
<!-- android:radius设置弧形的半径 -->
<corners android:radius="5dip"/>
</shape>
注意:如果想让当前的文本框取消聚焦,可定义两个<EditText>组件,第一个的EditView组件的Layout_hight
和Layout_width的属性值都是“0”即可。
创建一个EditView组件:在main.xml中创建
<EditText
android:hint="EditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLength="11"
android:singleLine="true"
android:inputType="phone"
android:background="@drawable/shape"
/>
android:hint="XXXX" 表示在文本框的后面出现背景文字
android:maxLength="" 表示文本框可输入的最大长度
android:singleLine="" 表示当前文本框所显示的的文字是否在同一行,属性值为true和false
android:inputType="" 表示当前文本框所输入文字的类型,可以是number phone等
android:background="" 调用一个.xml文件来进行设置文本框,上面的例子表示调用的是shape.xml文件
Shape.xml文件代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充颜色 -->
<solid android:color="#ffffff"/>
<!-- 设置四个角为弧形 -->
<!-- android:radius设置弧形的半径 -->
<corners android:radius="5dip"/>
</shape>
注意:如果想让当前的文本框取消聚焦,可定义两个<EditText>组件,第一个的EditView组件的Layout_hight
和Layout_width的属性值都是“0”即可。