Android——EditText自定义边框、圆角和其常用属性总结
2018-01-17 11:11
633 查看
属性总结:
id: 控件的唯一标识,代码中通过id来找到控件
background: 控件的背景,可以通过该属性来自定义控件不同状态下的外观
padding: 控件中文本内容距离控件边框的距离。单位:dp
paddingLeft: 文本到左边框的距离
paddingRight 文本到有边框的距离
layout_marginTop:margin 指控件之间的距离,top指该控件与它上方控件的间距
layout_marginLeft 该控件与它左侧控件的间距
layout_marginRight 该控件与它右侧控件的间距
layout_marginBottom 该控件与它下方控件的间距
textColor 文本颜色
maxLength 文本最大长度,即字符个数
inputType 输入文本的类型,常用的有number:数字;phone:电话号码;email:电子邮件
layout_width 该控件的宽度
layout_height 该控件的高度
hint: 提示文本内容,在点击后自动消失
=========================================================================================
执行步骤:
首先在/res/layout文件夹下创建custom_et_layout.xml布局文件,源代码如下:
再加上以下内容的渲染,才能得到一个有边框、圆角的EditText。
步骤:
1.在/res/drawable下创建文件bg_edittext_normal.xml,表示该文本框在常规情况下的样子,内容如下:
2.在/res/drawable下创建文件bg_edittext_focused.xml,表示该文本框在获得焦点情况下的样子,内容如下
shape中如果不通过android:shape来指定形状时,默认是矩形,其中solid代表纯色,corners代表角,radius越大,圆角越大,stroke代表边框线
3.在/res/drawable下创建文件bg_edittext.xml,在选择器中应用以上编写的两个样式,内容如下
最后在布局文件的指定控件中的android:background中应用该选择器,例如android:background=“@drawable/bg_edittext”
结束 效果图
转载自 http://blog.csdn.net/xuejingfu1/article/details/51597032
id: 控件的唯一标识,代码中通过id来找到控件
background: 控件的背景,可以通过该属性来自定义控件不同状态下的外观
padding: 控件中文本内容距离控件边框的距离。单位:dp
paddingLeft: 文本到左边框的距离
paddingRight 文本到有边框的距离
layout_marginTop:margin 指控件之间的距离,top指该控件与它上方控件的间距
layout_marginLeft 该控件与它左侧控件的间距
layout_marginRight 该控件与它右侧控件的间距
layout_marginBottom 该控件与它下方控件的间距
textColor 文本颜色
maxLength 文本最大长度,即字符个数
inputType 输入文本的类型,常用的有number:数字;phone:电话号码;email:电子邮件
layout_width 该控件的宽度
layout_height 该控件的高度
hint: 提示文本内容,在点击后自动消失
=========================================================================================
执行步骤:
首先在/res/layout文件夹下创建custom_et_layout.xml布局文件,源代码如下:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/alertDialog_et" android:background="@drawable/bg_edittext" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_marginTop="30dp" android:layout_marginLeft="25dp" android:layout_marginRight="30dp" android:layout_marginBottom="30dp" android:textColor="#008A00" android:maxLength="3" android:inputType="number" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入一个有效整数..."/> </RelativeLayout>
再加上以下内容的渲染,才能得到一个有边框、圆角的EditText。
步骤:
1.在/res/drawable下创建文件bg_edittext_normal.xml,表示该文本框在常规情况下的样子,内容如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@android:color/transparent" /> <corners android:radius="10dip"/> <stroke android:width="1dip" android:color="#BDC7D8" /> </shape>
2.在/res/drawable下创建文件bg_edittext_focused.xml,表示该文本框在获得焦点情况下的样子,内容如下
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@android:color/transparent" /> <corners android:radius="10dip"/> <stroke android:width="1dip" android:color="#728ea3" /> </shape>
shape中如果不通过android:shape来指定形状时,默认是矩形,其中solid代表纯色,corners代表角,radius越大,圆角越大,stroke代表边框线
3.在/res/drawable下创建文件bg_edittext.xml,在选择器中应用以上编写的两个样式,内容如下
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="false" android:drawable="@drawable/bg_edittext_normal" /> <item android:state_focused="true" android:drawable="@drawable/bg_edittext_focused" /> </selector>
最后在布局文件的指定控件中的android:background中应用该选择器,例如android:background=“@drawable/bg_edittext”
结束 效果图
转载自 http://blog.csdn.net/xuejingfu1/article/details/51597032
相关文章推荐
- Android——EditText自定义边框、圆角和其常用属性总结
- Android——EditText自定义边框、圆角和其常用属性总结
- Android UI设计之<四>自定义TextView属性,实现带边框效果的TextView
- Android中EditText常用属性与软键盘控制
- ImageView EditText 常用属性总结
- Android自定义EditText去除边框并添加下划线
- android:EditText属性/去边框
- EditText常用属性总结
- Android小记:EditText的两个常用属性
- Android EditText常用属性功能汇总
- Android之EditText自定义边框和边框颜色(转载)
- 自定义android控件EditText 自定义边框 背景
- 自定义android控件EditText 自定义边框 背景
- 【Android常用控件】EditText常用属性【三】:EditText选取操作
- 使用图片自定义android控件EditText 边框背景
- 自定义android控件EditText 自定义边框 背景
- Android给TextView和EditText等控件设置透明背景、圆角边框
- 自定义android控件EditText边框背景
- Android中TextView和EditView常用属性设置
- 使用图片自定义android控件EditText 边框背景