EditText的requestFocus()在运行android P(API 28)的设备上不起作用 [英] requestFocus() for EditText not working on devices running android P (API 28)

查看:98
本文介绍了EditText的requestFocus()在运行android P(API 28)的设备上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 EditText的接受OTP,一旦用户在字段中输入数字,用户便会专注于下一个 EditText .它在所有设备上都可以正常工作.但是在运行Android OS P的设备(即API 28)上, requestFocus()不起作用,并且用户无法在连续的 EditTexts 中输入数字因为焦点不会自动移动.

I am using EditText's to accept an OTP, where user has focus on next EditText once he enters a digit to a field and so. It works fine on all devices. But on devices running android OS P i.e. API 28, requestFocus() does not work, and user is not able to enter digits to consecutive EditTexts as focus doesn't move automatically.

这里是代码-默认情况下,所有 EditText的都被禁用,以防止打开系统键盘.我正在使用自己的 CustomKeybaord 接受数字.但是,它适用于Android P.

Here is the code - by default all EditText's are disable to prevent from opening system keyboard. I am using my own CustomKeybaord to accept numbers. However it works except Android P.

mEtCode1.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            Log.d("BEFORE_", charSequence.toString());
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            hideError(charSequence.toString());

            if (!charSequence.toString().isEmpty()) {
                mEtCode2.requestFocus();
                mEtCode1.setBackground(getResources().getDrawable(R.drawable.verify_code_edit_text_background));
                mEtCode2.setBackground(getResources().getDrawable(R.drawable.verify_code_edit_text_background));
                mEtCode1.setEnabled(false);
            }

        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

请帮助我

先谢谢您

推荐答案

在具有Android P sdk的设备上,我的OTP屏幕也遇到了相同的问题.问题是我将editText的高度和宽度设置为0dp,这在android P中禁用了焦点,如Android P更改日志中Android开发人员页面所述: android-9.0-changes-28#ui-changes

I had the same issue with my OTP screen on devices with Android P sdk. The problem was that i set the height and width of the editText to 0dp, which is focus disabling in android P, as described in Android Developer page in the Android P change log: android-9.0-changes-28#ui-changes

面积为0(宽度或高度为0)的视图不再可聚焦.

Views with 0 area (either a width or a height is 0) are no longer focusable.

这篇关于EditText的requestFocus()在运行android P(API 28)的设备上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆