1

私のアクセシビリティ サービスは、フォーカス可能なノードを通過します。これには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

問題は、レイアウト内のフォーカス可能なノードをどのように処理できるかということです。

4

2 に答える 2

3

これはよくある誤解です。探しているのは、入力フォーカスを取得できるオブジェクトです (EditText コントロールを考えてください)。これは、アクセシビリティ フォーカスとは根本的に異なります。レイアウトにフォーカス可能な入力コントロールがありません。

必要な機能は次のとおりです。

someAccessibilityNodeInfo.getTraversalAfter();

someAccessibilityNodeInfo.getTraversalBefore();

上/下に相当するものはありません。これは好きなように計算できますが。アクセシビリティのフォーカス可能なノードの階層全体を配列に格納し、x と y の位置に基づいて上下を計算できます。

于 2015-10-11T23:02:25.723 に答える
1

丁度!ツリーに存在するため、ビュー コンテナーが返されます。

必要なのは葉ノードです。

このコードは、フォーカス可能なノード (リーフ ノード) のリストを提供します。

ArrayList<AccessibilityNodeInfo> inputViewsList = new ArrayList<AccessibilityNodeInfo>();
AccessibilityNodeInfo rootNode = getRootInActiveWindow();
refreshChildViewsList(rootNode);
for(AccessibilityNodeInfo mNode : inputViewsList){
    if(mNode.isFocusable()){
        //do whatever you want with the node...
    }
}

refreshChildViewsList方法:

private void refreshChildViews(AccessibilityNodeInfo rootNode){
    int childCount = rootNode.getChildCount();
    for(int i=0; i<childCount ; i++){
        AccessibilityNodeInfo tmpNode = rootNode.getChildAt(i);
        int subChildCount = tmpNode.getChildCount();
        if(subChildCount==0){
            inputViewsList.add(tmpNode);
            return; 
        } else {
            refreshChildViews(tmpNode);
        } 
    } 
} 

このコードに問題がある場合はお知らせください。

于 2015-10-20T13:00:23.137 に答える