我正在做一个警告对话框的应用程序,我有一个问题,我的alertdialog显示在右侧,如果我把一个负面的两个是正确的我怎么能centerButtonButton?中心PositiveButton
public void showBandDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = LayoutInflater.from(getActivity());
final View view2 = inflater.inflate(R.layout.bluetooth_dialog, null);
if(bluetoothIsActive){
ImageView bluetootIndicator = (ImageView) view2.findViewById(R.id.bluetooth_indicator);
bluetootIndicator.setImageResource(R.drawable.checked);
}
if(bluetoothIsSaved){
ImageView bluetootSavedIndicator = (ImageView) view2.findViewById(R.id.bluetooth_saved_indicator);
bluetootSavedIndicator.setImageResource(R.drawable.checked);
}
builder.setTitle(Html.fromHtml("<font color='#55BFE7'>Bluetooth</font>"));
builder.setPositiveButton("Done",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {}
});
builder.setView(view2);
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button okButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
}
});
alertDialog.show();
}
您可以使用自定义布局文件,并根据您的要求放置按钮,只需调用builder.setView(R.layout.dialog_view);并为这些按钮设置OnClickListener –
我认为你不应该改变标准的对齐方式(右对齐的正负按钮) – Booger
您应该阅读对话设计指南https://www.google.com/design/ spec/components/dialogs.html# –