Android - 防止 TalkBack 大声宣布 TextView 标题 [英] Android - prevent TalkBack from announcing TextView title aloud

查看:25
本文介绍了Android - 防止 TalkBack 大声宣布 TextView 标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个可访问的 android 应用程序,人们将在其中使用通过触摸探索"和话语提示"辅助功能服务来使用我的应用程序.

I am developing an accessible android application where people would be using Explore by Touch and TalkBack accessibility services to use my application.

这是我的 Android XML 代码:

This is my Android XML code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/forename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="15dip"
        android:textSize="20sp"
        android:text="@string/forenameText" 
        android:contentDescription="@null"/>

    <EditText
        android:id="@+id/EditTextForename"
        android:layout_width="285dp"
        android:layout_height="65dp"
        android:layout_marginTop="10dip"
        android:layout_marginLeft="15dip"
        android:hint="@string/forenameHint"
        android:inputType="textPersonName"
        android:lines="1"
        android:singleLine="true"
        android:textSize="20sp" >
    </EditText>

</LinearLayout>

strings.xml

strings.xml

<string name="forenameText">Forename</string>
<string name="forenameHint">Enter your forename here</string>

TextView 显示标题Forename",EditText 允许我在表单字段中输入一些详细信息.我的问题是当我通过使用触摸浏览"在屏幕上拖动我的手指,TalkBack 会选择 TextView 的标题并大声宣布它为Forename".我希望 TextView 只显示文本而不提供任何声音反馈.

TextView displays the title "Forename" and EditText allows me to enter some details in the form field. The problem I have is that when I drag my finger across the screen by using Explore by Touch, TalkBack picks up the title of the TextView and announces it aloud as "Forename". I want the TextView to only display text and not provide any audible feedback.

正如您从上面的代码中看到的那样,我已将 contentDescription 设置为 @null,但是当我的手指位于文本视图.

I have set contentDescription to @null as you can see from the code above, but TalkBack still announces "Forename" when my finger is located over the TextView.

我也试过在我的 Java 类中设置 contentDescription:

I have also tried setting contentDescription in my Java class:

TextView forename=(TextView)findViewById(R.id.forename);
forename.setContentDescription("");

但是,我仍然遇到同样的问题.有没有其他方法可以将 contentDescription 设置为 null/empty 并防止 TalkBack 大声宣布它?

However, I still get the same problem. Is there any other way to set contentDescription to null/empty and prevent TalkBack from announcing it aloud?

Java 代码:

public class MainActivity extends Activity{

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        View forename = findViewById(R.id.forename);

        forename.setAccessibilityDelegate(new AccessibilityDelegate() {
          public boolean performAccessibilityAction (View host, int action, Bundle args){
            return true;
          }
        });
    }

}

推荐答案

我今天也尝试这样做,并且能够在 TextView<上设置 'empty' contentDescription/code> 像这样(使用不间断的空格):

I was trying to do the same today, and was able to set an 'empty' contentDescription on a TextView like so (using a non-breaking whitespace):

decorativeTextView.setContentDescription("u00A0"); 

现在 TalkBack 对那个 TextView 没有任何说明.

now TalkBack doesn't say anything for that TextView.

但我同意 Nick 关于在您的情况下将标签保留为可读的意见,因为提示仅读取空 EditTexts.

but I agree with Nick about leaving the label as readable in your case, because hint is only read for empty EditTexts.

这篇关于Android - 防止 TalkBack 大声宣布 TextView 标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆