MainActivity.java
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
activity_main.xml
<EditText
android:id="@+id/edit_text"
android:layout_width="200dp"
android:layout_height="60dp"
android:inputType="textPassword"></EditText>
MainActivity.java
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
calculatePasswordStrength(s.toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
MainActivity.kt
edit_text.addTextChangedListener(object : TextWatcher{
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
})
MainActivity.java
WEAK(R.string.weak, R.color.weak),
MEDIUM(R.string.medium, R.string.medium),
STRONG(R.string.strong, R.string.strong),
VERY_STRONG(R.string.very_strong, R.string.very_strong);
MainActivity.kt
WEAK {
override fun stringId(): Int = R.string.weak
override fun colorId(): Int = R.color.weak
},
MEDIUM {
override fun stringId(): Int = R.string.medium
override fun colorId(): Int = R.color.medium
},
STRONG {
override fun stringId(): Int = R.string.strong
override fun colorId(): Int = R.color.strong
},
VERY_STRONG {
override fun stringId(): Int = R.string.very_strong
override fun colorId(): Int = R.color.very_strong
};
abstract fun stringId(): Int
abstract fun colorId(): Int
Recommended Posts