我正在尝试在显示小吃店后立即发送可访问性。但是什么都没有播放。这是我在 onStart() 生命周期方法中的代码:
final Snackbar snackbar = Snackbar
.make(findViewById(R.id.container), "snackbars are cool", Snackbar.LENGTH_INDEFINITE);
snackbar.setActionTextColor(getResources().getColor(R.color.snackbar_actions));
View snackbarView = snackbar.getView();
snackbarView.setBackgroundColor(Color.DKGRAY);
TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.WHITE);
snackbar.show();
//time to send a accessibility event below
final ViewGroup parentView = (ViewGroup)findViewById(R.id.container);
if (parentView != null) {
final AccessibilityManager a11yManager =
(AccessibilityManager) this.getSystemService(Context.ACCESSIBILITY_SERVICE);
if (a11yManager != null && a11yManager.isEnabled()) {
final AccessibilityEvent e = AccessibilityEvent.obtain();
snackbarView.onInitializeAccessibilityEvent(e);
e.getText().add("some more text to say");
//nothing happens here
parentView.requestSendAccessibilityEvent(snackbarView, e);
}
}