我已经通过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();
出现对话框时,它会自动显示“警告对话框。这是我的警告对话框。确定。”但是我想控制它,就像它应该只读“警报对话”或“这是我的警报对话”等。
在点击“确定”时,它仅显示“确定”,而不是“确定按钮”。
最佳答案
如果我正确理解了您想要的内容,则可以实现一个自定义警报对话框,例如,完成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)在您选择的 View 上通过TalkBack设置您要读出的文本