为自定义对话框设置contentDescription

为自定义对话框设置contentDescription

本文介绍了为自定义对话框设置contentDescription的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开对话框时,如何设置一个 contentDescription 可以被辅助服务读取?我目前正在使用一个带有自定义布局的对话框来显示一个阻止的编码屏幕,并且说出 contentDescription 是Alert,这在这种情况下是不合适的。 >

感谢;)

解决方案

您可以创建子类对话框并覆盖 dispatchPopulateAccessibilityEvent 以提供您自己的辅助功能文本。



以下是一个例子:

  @Override 
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event){
if(event.getEventType()= = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED){
event.getText()。add(你的消息到这里);
返回true;
}
return super.dispatchPopulateAccessibilityEvent(event);
}


how can I set a contentDescription to be read by the accessibility service when my dialog is opened? I'm currently using a dialog with a custom layout to display a blocking laoding screen and the spoken contentDescription is "Alert", which is not appropriate in this circumstance.

Thanks ;)

解决方案

You can create subclass Dialog and override dispatchPopulateAccessibilityEvent to provide your own accessibility text.

Here's an example:

@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        event.getText().add("Your message goes here");
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}

这篇关于为自定义对话框设置contentDescription的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:41