我製作了一個AlertDialog
,它有三個按鈕(正面,負面,中性),當我在手機上測試時它工作正常(Android 7.0),但我有幾個朋友與Android 5.0和6.0)測試它們,他們只有中性按鈕顯示。AlertDialog僅在Android上顯示中性按鈕<7.0
下面是代碼:
AlertDialog.Builder isSelfieBuilder = new AlertDialog.Builder(context);
isSelfieBuilder.setTitle("Choose picture orientation.");
// Set up the buttons
isSelfieBuilder.setPositiveButton("Selfie", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Do something
}
});
isSelfieBuilder.setNeutralButton("Landscape", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Do something
}
});
isSelfieBuilder.setNegativeButton("Portrait", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Do something
}
});
final AlertDialog picTypeDialog = isSelfieBuilder.create();
picTypeDialog.show();
final Button positiveButton = picTypeDialog.getButton(AlertDialog.BUTTON_POSITIVE);
LinearLayout.LayoutParams positiveButtonLL = (LinearLayout.LayoutParams) positiveButton.getLayoutParams();
positiveButtonLL.width = ViewGroup.LayoutParams.MATCH_PARENT;
positiveButton.setLayoutParams(positiveButtonLL);
final Button neutralButton = picTypeDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
LinearLayout.LayoutParams neutralButtonLL = (LinearLayout.LayoutParams) neutralButton.getLayoutParams();
neutralButtonLL.width = ViewGroup.LayoutParams.MATCH_PARENT;
neutralButton.setLayoutParams(neutralButtonLL);
final Button negativeButton = picTypeDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
LinearLayout.LayoutParams negativeButtonLL = (LinearLayout.LayoutParams) negativeButton.getLayoutParams();
negativeButtonLL.width = ViewGroup.LayoutParams.MATCH_PARENT;
negativeButton.setLayoutParams(negativeButtonLL);
任何人有任何想法,爲什麼我只在那裏得到的中性按鈕?我嘗試刪除對齊部分(.show()
後的所有內容),但我得到了相同的結果。我正在使用API 21(5.0)的模擬器上測試,並且遇到同樣的問題。
確定它必須使用android版本做些什麼?也許更多的屏幕尺寸導致它.... – Opiatefuchs