我正在制作一个带有警告对话框的应用程序,我有一个问题,我的警告对话显示在右侧,如果我把一个负面,两个是在右边,我怎么能将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();
}
答案 0 :(得分:1)
您始终可以使用Neutral Button
来实现正面按钮的相同效果,而无需为对话框创建特定的布局文件。
AlertDialog.Builder - Neutral Button
另外:Android: Difference between positive, negative, and neutral button
答案 1 :(得分:1)
您可以使用自定义布局,例如,当您想要显示某些通知时,会创建一个额外的活动。要从此通知活动接收数据,您可以使用startActivityForResult()启动它,并在收到此操作时执行某些操作。 您可以在清单中使用的自定义通知活动:
<activity
android:name=".NotifiactionActivity"
android:theme="@android:style/Theme.Holo.Light.Dialog" >
</activity>
您可以使用其他主题,但它似乎是一种警报。
答案 2 :(得分:0)
使用AlertDialog(或建议使用中性按钮)是不可能的,您必须创建自己的自定义对话框。