我的屏幕有图像和标题视图。当页面加载时,我需要将TalkBack公告作为标题文本。但它总是宣布ImageView的contentDescription。
视图层次结构
ImageView然后是标题。
我尝试了什么?
尝试将焦点设置在标题上, 为此,我将这些属性设置为ImageView
android:focusable="false"
android:accessibilityTraversalAfter="@id/title"
android:importantForAccessibility="no"
很不幸,这些方法在我的情况下都没有奏效。作为第二次尝试,我将它们添加到我的片段中。
onResume {
if (accessibilityManager?.isEnabled == true) {
activity.title = title
activity.window.decorView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
}
}
还是不起作用!! ImageView 的 contentDescription 有这么大的能量吗?
加载页面时需要宣布 标题 文本,如果用户点击(或向左/向右滑动),则 ImageView 的描述需要被宣布。
XML ....
<data>
.....
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/vertical_padding"
android:theme="@style/CL.Theme.Light">
<ImageView
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_close"
android:importantForAccessibility="no"
android:contentDescription="CLOSE"
android:accessibilityTraversalAfter="@id/title"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="BACK"
android:src="@drawable/icon_back"
android:importantForAccessibility="no"
android:accessibilityTraversalAfter="@id/title
android:layout_margin="@dimen/icon_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.core.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/back_button"
app:layout_constraintBottom_toTopOf="@id/primary_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|clip_horizontal"
android:paddingStart="@dimen/horizontal_padding"
android:paddingTop="@dimen/error_screen_top_offset"
android:paddingEnd="@dimen/horizontal_padding"
android:paddingBottom="@dimen/vertical_padding">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/margin_top"
android:gravity="center"
android:text="HEADER TITLE"
android:focusable="true"
android:focusableInTouchMode="true"
android:importantForAccessibility="yes"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginTop="62dp"
tools:text="Title" />
<TextView
android:id="@+id/subtitle
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/subtitle_margin_top"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title"
tools:text="Subtitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/cta_margin_top"
android:layout_marginStart="@dimen/horizontal_padding"
android:layout_marginEnd="@dimen/horizontal_padding"
android:layout_marginBottom="@dimen/secondary_cta_margin"
/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/horizontal_padding"
android:layout_marginEnd="@dimen/horizontal_padding"
android:gravity="center"
/>
</androidx.constraintlayout.widget.ConstraintLayout>