如何disable/Manage ImageView上的辅助功能公告? Android
How to disable/Manage Accessibility announcement on ImageView? Android
我的屏幕有图像和标题视图。我需要在页面加载时宣布对讲作为标题文本。但它总是宣布 ImageView 的 contentDescription。
查看层次结构
ImageView 然后是标题。
我尝试了什么?
试图将焦点设置在标题上,
为此,我将这些属性设置为 ImageView
android:focusable="false"
android:accessibilityTraversalAfter="@id/title"
android:importantForAccessibility="no"
运气不好,none 这些方法对我有用。作为第二次尝试,我在我的片段中添加了这些
onResume {
if (accessibilityManager?.isEnabled == true) {
activity.title = title
activity.window.decorView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
}
}
还是不行!! ImageView 的 contentDescription 有这么强大吗?
我需要在页面加载时宣布 title 文本,如果用户点击(或滑动 left/right),则 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>
从不同的 Whosebug 找到更好的解决方案 question
希望这能够帮助其他面临类似问题的人。
fun View?.requestAccessibilityFocus(): View? {
this?.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null)
this?.sendAccessibilityEvent(TYPE_VIEW_SELECTED)
return this
}
我的屏幕有图像和标题视图。我需要在页面加载时宣布对讲作为标题文本。但它总是宣布 ImageView 的 contentDescription。
查看层次结构
ImageView 然后是标题。
我尝试了什么?
试图将焦点设置在标题上, 为此,我将这些属性设置为 ImageView
android:focusable="false"
android:accessibilityTraversalAfter="@id/title"
android:importantForAccessibility="no"
运气不好,none 这些方法对我有用。作为第二次尝试,我在我的片段中添加了这些
onResume {
if (accessibilityManager?.isEnabled == true) {
activity.title = title
activity.window.decorView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
}
}
还是不行!! ImageView 的 contentDescription 有这么强大吗?
我需要在页面加载时宣布 title 文本,如果用户点击(或滑动 left/right),则 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>
从不同的 Whosebug 找到更好的解决方案 question
希望这能够帮助其他面临类似问题的人。
fun View?.requestAccessibilityFocus(): View? {
this?.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null)
this?.sendAccessibilityEvent(TYPE_VIEW_SELECTED)
return this
}