技术方案来自 https://blog.csdn.net/gongjdde/article/details/98358618
发现华为手机安全键盘模式下无法弹出Toast, 修复如下
1. 在EditText中加上digits属性
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_verify_code"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="验证码"
android:digits="@string/input_num_and_abc"
android:inputType="textPassword"
android:singleLine="true"
android:textSize="13dp" />
2. 代码中做如下设置就可以了
if (ModelUtils.isEMUI() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
binding.etVerifyCode.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_NORMAL
binding.etVerifyCode.transformationMethod = PasswordTransformationMethod.getInstance()
}
3. 为什么就可以了呢?
其实这是一个intputType=textPassword的Bug. 那么修改思路就是我们将输入框改成普通的text类型,
同时手动设置transformationMethod即可.