How to make TalkBack read TextView error message automatically?

纵然是瞬间 提交于 2019-12-04 09:14:33

You can explicitly read out the error message through announceForAccessibility("mesage") function provided by View

editText.setError("message")
editText.announceForAccessibility("message");

Please note that this function was added in API level 16.

update 1: Set the error message to null when the text is changed in EditText to prevent reading error message again and again.

 editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                editText.setError(null);
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!