3
如何將AlertDialog中的項目與由dialog.setItems()創建的中心對齊?Android AlertDialog設置對齊中心的項目
例如,這將創建與默認左對齊數次選項對話框:
AlertDialog.Builder timeOutDialog = new AlertDialog.Builder(getActivity());
timeOutDialog.setTitle("Set Timer");
final String[] types = {"5 min", "15 min", "30 min", "1 hour", "3 hours", "6 hours", "12 hours", "24 hours"};
timeOutDialog.setItems(types, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
switch(which){
case 0: // 5m
timerLength = 0;
break;
case 1: // 15m
timerLength = 1;
break;
// ...
}
timeOutButton.setText(types[which]);
}
});
AlertDialog dialog = timeOutDialog.show();
我知道有ID的設置對齊的標題和消息。是否有標識和消息(例如android.R.id.message)允許設置對齊ID?
我搜索了答案,許多人說這樣做的唯一方法是膨脹對話框或創建一個自定義對話框xml與自定義中心微調。那些是我唯一的選擇嗎?
感謝您指出這個好的圖書館。 –