在警报对话中自定义Android对讲?

Tau*_*qir 9 android android-alertdialog accessibilityservice talkback

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

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();
Run Code Online (Sandbox Code Playgroud)

当出现对话框时,它会自动读取"Alert Dialogue.这是我的提醒对话.确定." 但我想控制它,就像它应该只读"警报对话"或"这是我的警报对话"等.

点击"确定"时,它只读"OK",而不是"OK按钮".

Tem*_*haf 1

如果我正确理解你想要什么,你可以实现一个自定义警报对话框,例如像这里所做的那样,相关代码示例:

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();
Run Code Online (Sandbox Code Playgroud)

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

  • 您好@Templerschaf,它读取按钮内容描述。感谢那。但我不能接受这个答案,因为它是部分正确的。对话打开后,它会自动读取内容。我也需要定制它。 (2认同)
  • @Templerschaf,问题仍然存在。它仍然自动读取内容。 (2认同)