標籤:android android教程 android開發 edittext layout
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 情緒控_
一起學android之EditText的各種使用(15)