私のアクセシビリティ サービスは、フォーカス可能なノードを通過します。これにはfocusSearch関数を使用しようとしていますが、ノードが返されません。ただし、レイアウトにはフォーカス可能なアイテムが含まれています。レイアウトは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:text="Button" />
<TextView
android:id="@+id/text"
android:layout_width="122dp"
android:layout_height="fill_parent"
android:text="Hello World2" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:focusable="true"
android:text="Button2" />
</LinearLayout>
だから私が試したのは、最初のボタンを見つけることです:
AccessibilityNodeInfo root = getRootInActiveWindow();
AccessibilityNodeInfo node1 = null;
node1 = root.findAccessibilityNodeInfosByViewId("my.app:id/button1").get(0);
//returns button view
node1 = root.focusSearch(View.FOCUS_DOWN); //returns null
node1 = root.focusSearch(View.FOCUS_LEFT); //returns null
node1 = root.focusSearch(View.FOCUS_RIGHT); //returns null
node1 = root.focusSearch(View.FOCUS_FORWARD); //returns null
ただし、findFocusを使用すると、フレームレイアウトが返されます
node1 = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
//returns node of the main framelayout
次に、このノードを次の検索に使用しましたが、何も見つかりませんでした。
node1 = node1.focusSearch(View.FOCUS_FORWARD); //returns null
findfocus
そして、代わりに呼び出すとfocusSearch
、同じノードが返されました
node1 = node1.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
//returns the same node
問題は、レイアウト内のフォーカス可能なノードをどのように処理できるかということです。