首页 > 解决方案 > 如何向 FragmentContainerView 添加可访问性委托?

问题描述

我需要添加与我的应用程序集成的 Google 地图的可访问性。我正在使用FragmentContainerView集成SupportMapFragment. 我的 XML 看起来像:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.fragment.app.FragmentContainerView
    android:id="@+id/google_map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="270dp"
    android:layout_marginTop="32dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:context=".MapsActivity" />

</androidx.constraintlayout.widget.ConstraintLayout>

在我的 MainFragment 中,我试图将可访问性委托设置为 google_map

    google_map.accessibilityDelegate = object : View.AccessibilityDelegate() {
        override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo?) {
            super.onInitializeAccessibilityNodeInfo(host, info)
            Log.d("***", "Inside onInitializeAccessibilityNodeInfo")
        }
    }

但是在这种情况下accessibilityDelegate 不起作用。实际上onInitializeAccessibilityNodeInfo方法没有被调用。你能帮我解决这个问题吗?

标签: androidaccessibilityandroid-accessibility

解决方案


推荐阅读