Android開發(fā)手冊TextInputLayout樣式使用示例
前言
前面小空帶同學們學了EditText控件,又用其實踐做了個驗證碼功能,以為這就完了嗎?
然而并沒有。
Android在5.0以后引入了Materia Design庫的設計,現(xiàn)在又有了Jetpack UI庫的設計。幫助開發(fā)者更高效的實現(xiàn)炫酷的UI界面,降低開發(fā)門檻。
Jetpack我們后面再說,承接之前的EditText,先說說Materia Design里的TextInputLayout。
使用方式是將TextInputEditText或EditText套到TextInputLayout內,這樣友情提示信息hit就可以帶有動畫(上浮為標題),計數(shù)/密碼可見等屬性設置。
布局代碼
<com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="請輸入用戶名"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:hint="請輸入密碼"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" /> </com.google.android.material.textfield.TextInputLayout>
這樣就簡單的實現(xiàn)了一個效果。我們在繼續(xù)深入添加些屬性:
<com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="請輸入用戶名" app:hintAnimationEnabled="false"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:hint="請輸入密碼" app:counterEnabled="true" app:counterMaxLength="10" app:passwordToggleEnabled="true"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" /> </com.google.android.material.textfield.TextInputLayout>
從運行結果可以看出,設置了字數(shù)限制后,自動在編輯框右下角顯示最大字數(shù)和當前輸入字數(shù)(隨著輸入情況實時變化),并且更改了顏色樣式
??屬性介紹
- app:boxCollapsedPaddingTop 設置用于編輯文本在框模式下折疊的頂部填充的值
- app:boxStrokeErrorColor 在顯示錯誤時設置輪廓框的描邊顏色。
- app:boxStrokeWidth 設置描邊的寬度
- app:boxStrokeWidthFocused 設置獲取焦點框的描邊寬度
- app:counterEnabled 是否顯示計數(shù)器
- app:counterMaxLength 設置計數(shù)器的最大值,與counterEnabled同時使用
- app:counterTextAppearance 計數(shù)器的字體樣式
- app:counterOverflowTextAppearance 輸入字符大于我們限定個數(shù)字符時的字體樣式
- app:errorEnabled 是否顯示錯誤信息
- app:errorTextAppearance 錯誤信息的字體樣式
- app:endIconCheckable 設置是否顯示結束圖標
- app:endIconContentDescription 為結束圖標設置內容說明
- app:endIconDrawable 設置結束圖標圖像
- app:endIconMode 設置模式
- app:endIconTintMode 指定混合模式,用于將 指定的色調應用于可繪制的結束圖標。
- app:helperText 設置幫助文本
- app:helperTextEnabled 設置是否激活幫助文本
- app:helperTextTextColor 設置幫助文本顏色
- app:hintAnimationEnabled 是否顯示hint的動畫,默認true
- app:hintEnabled 是否使用hint屬性,默認true
- app:hintTextAppearance 設置hint的文字樣式(指運行動畫效果之后的樣式)
- app:passwordToggleDrawable 設置密碼開關Drawable圖片,于passwordToggleEnabled同時使用
- app:passwordToggleEnabled 是否顯示密碼開關圖片,需要EditText設置inputType
- app:passwordToggleTint 設置密碼開關圖片顏色
- app:passwordToggleTintMode 設置密碼開關圖片(混合顏色模式),與passwordToggleTint同時使用
以上就是Android開發(fā)手冊TextInputLayout樣式使用示例的詳細內容,更多關于Android開發(fā)TextInputLayout樣式的資料請關注腳本之家其它相關文章!
相關文章
Kotlin中常見內聯(lián)擴展函數(shù)的使用方法教程
在Kotlin中,使用inline修飾符標記內聯(lián)函數(shù),既會影響到函數(shù)本身, 也影響到傳遞給它的Lambda表達式,這兩者都會被內聯(lián)到調用處。下面這篇文章主要給大家介紹了關于Kotlin中常見內聯(lián)擴展函數(shù)的使用方法,需要的朋友可以參考下。2017-12-12Android開發(fā)之PopupWindow創(chuàng)建彈窗、對話框的方法詳解
這篇文章主要介紹了Android開發(fā)之PopupWindow創(chuàng)建彈窗、對話框的方法,結合實例形式詳細分析了Android使用PopupWindow創(chuàng)建對話框相關操作技巧,需要的朋友可以參考下2019-03-03Android 中CheckBox的isChecked的使用實例詳解
這篇文章主要介紹了Android 中CheckBox的isChecked的使用實例詳解的相關資料,需要的朋友可以參考下2017-04-04Android ListView之setEmptyView正確使用方法
這篇文章主要介紹了Android ListView之setEmptyView正確使用方法的相關資料,希望通過本文能幫助到大家使用該方法,需要的朋友可以參考下2017-09-09Android實現(xiàn)可拖拽帶有坐標尺進度條的示例代碼
這篇文章主要為大家詳細介紹了如何利用Android實現(xiàn)可拖拽帶有坐標尺進度條的效果,文中的示例代碼講解詳細,需要的小伙伴可以參考一下2023-06-06