簡體   English   中英

Android 輔助功能在 TextInputLayout 中不起作用

[英]Android Accessibility not working in TextInputLayout

如果在 TextInputEditText 中沒有輸入文本,Android 輔助功能對話將讀取 TextInputLayout 中的提示。

但是,如果在 TextInputEditText 中添加了文本,Android Talkback 將不會讀取 TextInputLayout 中的提示。

我需要輔助功能對講來始終閱讀 TextInputLayout 中的提示。

有誰知道怎么做?

謝謝你們

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:labelFor="@+id/editText"
            android:hint="username">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </com.google.android.material.textfield.TextInputLayout>

您可以將其覆蓋為的唯一方法:

延長 :

public class CustomTextInputLayoutAccessibilityDelegate extends TextInputLayout.AccessibilityDelegate {...}

然后覆蓋:

public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {

...
// And add the new logic in here:

        if (showingText) {
            if (hasHint) {
                info.setText(String.format("%s, %s", hintText, text));
            } else {
                info.setText(text);
            }
        } else if (hasHint) {
            info.setText(hintText);
        }


}

並將其設置為您的 TextInputLayout 為:

setTextInputAccessibilityDelegate(new CustomTextInputLayoutAccessibilityDelegate(this));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM