Swa*_*nil 6 android android-alertdialog
我正在使用带有两个按钮的警告对话框.这里的问题是每当我的警告对话框显示时,其显示的负按钮都会突出显示.这个对话框中只发生这种情况,其他工作正常.请提出一些解决方法.
这是代码:
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Stop On The Go!");
alert.setMessage(getResources().getString(R.string.tx_confirm_msg_journey));
alert.setPositiveButton("Stop",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
stopTask();
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
navigateToHomePage();
dialog.cancel();
}
});
alert.show();
Run Code Online (Sandbox Code Playgroud)
显示以下代码只需更改一行. alert.show().getButton(DialogInterface.BUTTON_POSITIVE).requestFocus();
AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
alert.setTitle("Stop On The Go!");
alert.setMessage(getResources().getString(R.string.tx_confirm_msg_journey));
alert.setPositiveButton("Stop",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
stopTask();
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
navigateToHomePage();
dialog.cancel();
}
});
alert.show().getButton(DialogInterface.BUTTON_POSITIVE).requestFocus();
Run Code Online (Sandbox Code Playgroud)
只是专注于积极
在您的肯定按钮中添加此行
alertDialog.setOnShowListener(new DialogInterface.OnShowListener(){
@Override
public void onShow(DialogInterface dialog) {
Button positive= alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.setFocusable(true);
positive.setFocusableInTouchMode(true);
positive.requestFocus();
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4858 次 |
| 最近记录: |