AndroidEditText常用属性
一、 说明
本文主要讲Android的EditText的一些常用的基本属性
二、 所用工具
Android Studio
三、 EditText常用属性
1. hint:设置EditText中的提示内容
2. textColorHint: 设置EditText中的提示内容的字体颜色
3. selectAllOnFocus:
值为true时点击该文本框时选中框中的已有的文本
值为false时点击该文本框时不会选中已有的文本
4. inputType:限制该文本框的输入内容,如number(限制为拨号建盘输入)
5. marginXXX:设置与外部组件的间隔
6. paddingXXX:设置与内部边框的间隔
7. textSize:设置字体大小
8. text:设置该文本框的初始内容
四、 例子代码
<LinearLayout
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"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/border"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="账号:"
android:textSize="25dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="12345"
android:textColorHint="#cccccc"
android:selectAllOnFocus="true"
android:inputType="number"
android:textSize="25dp"
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
五、 效果图
下图为点击该文本框时,选文本框中已有文本的效果图