【進階篇】Android學習筆記——TextInputLayout,textinputlayout

來源:互聯網
上載者:User

【進階篇】Android學習筆記——TextInputLayout,textinputlayout

Google為了統一Android系統的視覺和使用體驗而提出的一個新的標準,這就是Android Design。為了讓舊的系統也能相容新的標準,Google提供了Android Design Support Library包,在此包中,Android提供了很多新的控制項。而TextInputLayout正是來自於Android Design Support Library包。

TextInputLayout是一個新的布局,從繼承樹上看,它繼承自LinearLayout,但是它並不支援android:orientation屬性,因為TextInputLayout和ScrollView一樣,只能在其中遷入唯一的控制項。另外從TextInputLayout這個布局的名稱可以猜出,這是一個專門針對文本輸入動作而設計的布局。所以TextInputLayout一般是EditText或者AutoCompleteTextView這樣的控制項,TextInputLayout為這些控制項提供了體驗更好的顯示和體驗效果。

這裡以一個包含EditText的樣本,示範一下TextInputLayout的用法和效果。其布局檔案如下:

<android.support.design.widget.TextInputLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    app:counterEnabled="true"    app:counterMaxLength="5"    app:hintAnimationEnabled="true"    app:counterOverflowTextAppearance="@android:style/TextAppearance.DeviceDefault.Large">    <EditText        android:id="@+id/password"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:inputType="textPassword"        android:maxLines="1"        android:hint="@string/prompt_password"        android:singleLine="true" /></android.support.design.widget.TextInputLayout>

其中的app是為了使用Android Design Support Library包提供的新屬性,而進行的一個申明,只需要在布局檔案的根項目上引入以下的命名空間即可。

xmlns:app="http://schemas.android.com/apk/res-auto"

布局檔案設定完畢,運行效果如所示:

點擊這裡

 

 

==============================

 更多內容,歡迎查看本人部落格:林彥君的部落格

==============================

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.