Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customise Android Talkback in Alert Dialogue?

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".

like image 812
Mohammad Tauqir Avatar asked Aug 11 '15 09:08

Mohammad Tauqir


People also ask

What is custom dialogue in Android?

The custom dialog uses DIALOG to create custom alert in android studio. Dialog display a small window i.e a popup which draws the user attention over the activity before they continue moving forward. The dialog appears over the current window and display the content defined in it.

How to create custom dialog fragment in Android?

To create a DialogFragment , first create a class that extends DialogFragment , and override onCreateDialog() , as shown in the following example. Similar to how onCreateView() should create a root View in an ordinary fragment, onCreateDialog() should create a Dialog to display as part of the DialogFragment .

What is alert dialog in Android?

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.


1 Answers

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)

like image 91
Templerschaf Avatar answered Oct 18 '22 21:10

Templerschaf