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: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: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
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))
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>
效果如下:
转载请注明出处:http://blog.csdn.net/hai_qing_xu_kong/article/details/42584999 情绪控_