我們?cè)谧鲎?cè)登錄的時(shí)候逐工,經(jīng)常需要實(shí)現(xiàn)密碼的顯示切換問(wèn)題爹袁,如下圖所示:
明文顯示:
open_state.png
暗文顯示:
close_state.png
這時(shí)候我們就需要?jiǎng)討B(tài)的進(jìn)行狀態(tài)切換,那么我們?cè)撊绾螌?shí)現(xiàn)呢砸抛?
其實(shí)EditText提供了相應(yīng)的屬性:
//顯示密碼
private fun showText(){
mEditText.transformationMethod = HideReturnsTransformationMethod.getInstance()
}
//隱藏密碼
private fun hindText(){
mEditText.transformationMethod = PasswordTransformationMethod.getInstance()
}
就是如此的簡(jiǎn)單,好記性不如爛筆頭树枫,特記錄一下( ̄▽ ̄)"直焙。