9

I've checked with all default alert dialogue box via Android TalkBack. Default Android Talkback behaviour is that it reads all contents(non stop) in dialogue box. Is there any way I can customise it according to my need. For example :

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();

When dialog appears, it reads automatically "Alert Dialogue. This is my alert dialogue. OK." But I want to control it, like it should read only "Alert Dialogue" or "This is my alert dialogue" etc.

And while tapping on "OK" it reads only "OK", instead "OK button".

Ziem
  • 6,579
  • 8
  • 53
  • 86
Mohammad Tauqir
  • 1,817
  • 1
  • 18
  • 53

1 Answers1

1

If I understood correctly what you want, you could implement a custom alert dialog, for example like it is done here, relevant codesample:

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();

and then set the text you want read out by TalkBack on the Views of your choosing with View.setContentDescription(text)

Templerschaf
  • 142
  • 1
  • 8
  • I tried this, but the voice is reading the whole alertbox anyways – Carlo Moretti Aug 26 '15 at 08:29
  • 2
    Hi @Templerschaf, it reads the button content description. Thanks for that. But I cannot accept this answer as it is partially correct. Once dialogue opens, it reads the content automatically. I need to customise that also. – Mohammad Tauqir Aug 26 '15 at 09:34
  • 1
    You can [mute](http://stackoverflow.com/a/16469954/3309562) elements with View.setContentDescription("\u00A0") and you can force them to be read by [shifting the focus](http://stackoverflow.com/a/13303106/3309562) with View.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) – Templerschaf Aug 26 '15 at 10:43
  • @Templerschaf I tried changing the whole view's content description, but it is never red, it seems as a default Android behaviour to me. – Carlo Moretti Aug 26 '15 at 14:20
  • 2
    @Templerschaf, issue still persists. It still reads the content automatically. – Mohammad Tauqir Aug 26 '15 at 14:24