[英]Why does my negative button appear on the left side of my alert dialog?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Do you want to continue?");
builder.setMessage("Press Yes or No");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(MainActivity3.this,MainActivity.class);
startActivity(intent);
}
});
正面按鈕出現在右側而不是左側。
默認情況下,AlertDialog 將正面按鈕放在右側(如果您有從左到右的閱讀設置)。 AlertDialog 受閱讀方向設置的影響,因此它會根據布局方向而改變:
getWindows().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
如果您想交換按鈕,評論中建議的內容將起作用:
這會讓用戶感到困惑,因為他們希望正面按鈕位於右側(對於 LtR 讀者)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.