EditText它与TextVew十分相似,TextView是用来显示文本,并没有录入文本的功能,但EditText可以录入文本,接下来我们看看EditText常用的属性

效果1:

<span style="font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#ffffff"    android:orientation="vertical"    android:gravity="center" >    <EditText        android:id="@+id/tv_weixin"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:gravity="center"         android:hint="请输入ID"/></LinearLayout></span>

一起学android之EditText的各种使用(15)_第1张图片

android:layout_width="fill_parent":宽度填充父容器

android:layout_height="wrap_content":高度包裹内容

android:layout_marginLeft="8dp":距离左边距8dp
android:layout_marginRight="8dp":距离右边距8dp

android:gravity="center":内容居中

我们通过android:hint来指定文本框的提示信息


效果2:

<span style="font-size:18px;"> <EditText        android:id="@+id/tv_weixin"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:gravity="center"        android:inputType="numberPassword" /></span>

一起学android之EditText的各种使用(15)_第2张图片

通过android:inputType="numberPassword"来指定输入数字密码

inputType可以指定很多参数,比如:number 表示是一个数字框;data 表示输入日期;


下面通过background来定制一些比较炫的效果

1、

<span style="font-size:18px;"><EditText        android:id="@+id/tv_weixin"        android:layout_width="fill_parent"        android:layout_height="30dp"        android:layout_marginLeft="8dp"        android:layout_marginRight="8dp"        android:gravity="center"        android:background="@drawable/weixin3" /></span>
weixin3文件:

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <solid android:color="#0000"/>    <stroke android:width="3dp"        android:color="#3f5"/></shape></span>
效果如下:设置背景色为透明,边框为绿色,宽度3dp

一起学android之EditText的各种使用(15)_第3张图片

2、将以上的background属性设置以下文件

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item>        <shape android:shape="rectangle">            <solid android:color="#0ac39e" />        </shape>    </item>       <item android:left="2dp"        android:right="2dp"        android:bottom="2dp">        <shape android:shape="rectangle">            <solid android:color="#ffffff"/>        </shape>    </item>     <item android:bottom="6dp">        <shape android:shape="rectangle">            <solid android:color="#ffffff" />          </shape>    </item></layer-list></span>

效果如下(此效果是通过 任玉刚的博客(http://blog.csdn.net/singwhatiwanna/article/details/42215847))

一起学android之EditText的各种使用(15)_第4张图片


3、

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item>        <shape android:shape="oval" >            <solid android:color="#0ac39e" />        </shape>    </item>    <item android:top="6dp"        android:bottom="6dp">        <shape android:shape="rectangle" >            <solid android:color="#ffffff" />        </shape>    </item>    <item android:bottom="6dp"        android:top="6dp">        <shape android:shape="rectangle" >            <solid android:color="#ffffff" />        </shape>    </item>    <item android:left="2dp"        android:right="2dp"        android:top="2dp"        android:bottom="6dp">        <shape android:shape="rectangle">            <solid android:color="#ffffff"/>        </shape>    </item>     <item android:left="2dp"        android:right="2dp"        android:top="6dp"        android:bottom="2dp">        <shape android:shape="rectangle">            <solid android:color="#ffffff"/>        </shape>    </item></layer-list></span>
效果如下:

一起学android之EditText的各种使用(15)_第5张图片




转载请注明出处:http://blog.csdn.net/hai_qing_xu_kong/article/details/42584999情绪控_





更多相关文章

  1. Android 在界面中显示以及输入文本信息 TextView和EditText
  2. Android SeekBar自定义使用图片和颜色显示
  3. RecyclerView item imageview 图片宽高自适应
  4. android中TextView跑马灯效果
  5. Android背景渐变色效果
  6. Android实现程序前后台切换效果
  7. Android 微信分享,微信分享图片

随机推荐

  1. Android源码设计模式分析一期发布
  2. AndEngine进阶之自定义可拖动的背景
  3. Android(安卓)2.2 带来全新拍照增强特性
  4. 【翻译】App Architecture (Android架构
  5. 刨根问底-论Android“沉浸式”
  6. Handler 消息传递机制
  7. Android(安卓)适配Dark Theme(暗黑模式)
  8. 对Android中XML解析的小结
  9. Android(安卓)开发之对拍照和录像功能的
  10. 欢迎加入Java和Android架构知识星球