【问题标题】:Customise Android Talkback in Alert Dialogue?在警报对话框中自定义 Android 对讲?
【发布时间】:2015-09-01 00:49:55
【问题描述】:

我已通过 Android TalkBack 检查了所有默认警报对话框。默认的 Android 对讲行为是它读取对话框中的所有内容(不间断)。有什么方法可以根据我的需要定制它。 例如:

AlertDialog alertDialog = new AlertDialog.Builder(AlertDialogActivity.this).create();
alertDialog.setTitle("Alert Dialog");
alertDialog.setMessage("This is my alert dialog");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
    }
});

alertDialog.show();

当对话框出现时,它会自动读取“警报对话。这是我的警报对话。好的。”但我想控制它,就像它应该只读取“警报对话”或“这是我的警报对话”等。

点击“确定”时,它只显示“确定”,而不是“确定按钮”。

【问题讨论】:

    标签: android android-alertdialog talkback accessibilityservice


    【解决方案1】:

    如果我正确理解你想要什么,你可以实现一个自定义警报对话框,例如像它完成here,相关代码示例:

    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.dialog);
    dialog.setTitle("Android Custom Dialog Box");
    TextView txt = (TextView) dialog.findViewById(R.id.txt);
    txt.setText("This is an Android custom Dialog Box Example! Enjoy!");
    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButton);
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
    
    dialog.show();
    

    然后使用View.setContentDescription(text)在您选择的视图上设置您想要由 TalkBack 读出的文本

    【讨论】:

    • 我试过了,但声音还是在读取整个警报框
    • 嗨@Templerschaf,它读取按钮内容描述。感谢那。但我不能接受这个答案,因为它部分正确。一旦对话打开,它会自动读取内容。我也需要自定义它。
    • 您可以使用 View.setContentDescription("\u00A0") mute 元素,您可以使用 View.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) 强制 shifting the focus 读取它们
    • @Templerschaf 我尝试更改整个视图的内容描述,但它从不是红色的,这对我来说似乎是默认的 Android 行为。
    • @Templerschaf,问题仍然存在。它仍然会自动读取内容。
    猜你喜欢
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多