一起學android之EditText的各種使用(15)

來源:互聯網
上載者:User

標籤: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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.