【发布时间】:2016-03-14 12:57:17
【问题描述】:
对于 API 16,正面和负面按钮位于另一个下方。在 API 19 及更高版本中,它们位于同一行。更改字体不会更改位置。如何让两个按钮位于同一行?
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.resume_session)
.setMessage(R.string.session_question)
.setPositiveButton(R.string.continue_session, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
setDataAndStart(dataHelper, exDB);
}
})
.setNegativeButton(R.string.restart_session, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
exDB.resetCurrentWorkoutRecords();
setDataAndStart(dataHelper, exDB);
}
});
final AlertDialog pendingWorkoutAlert = builder.create();
//check for dp size of the phone and then change font
if (AppApplication.displayType.equals("normal")) {
pendingWorkoutAlert.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button btnPositive = pendingWorkoutAlert.getButton(Dialog.BUTTON_POSITIVE);
btnPositive.setTextSize(14);
Button btnNegative = pendingWorkoutAlert.getButton(Dialog.BUTTON_NEGATIVE);
btnNegative.setTextSize(14);
}
});
}
return pendingWorkoutAlert;
【问题讨论】:
-
可以使用支持库的AlertDialog类或者DialogFragment类。
-
请出示你的xml
-
@barq 我已经添加了代码。没有xml
标签: android android-alertdialog android-dialogfragment dialogfragment