Я бы просто сделать свой собственный класс для имитации AlertDialog, таким образом, вы можете использовать свой собственный макет без прикрепленных шнуров. (Есть некоторые странные проблемы, когда вы не можете полностью избавиться от фрейма, если хотите полностью стилизованный AlertDialog). Что-то вроде этого, но вы можете развернуть это как можно полнее:
public class CustomDialog extends Dialog {
private Button positive, negative;
public CustomDialog(Context context) {
super(context);
initialize(context);
}
protected CustomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
initialize(context);
}
public CustomDialog(Context context, int theme) {
super(context, theme);
initialize(context);
}
private void initialize(Context c) {
//Inflate your layout, get a handle for the buttons
positive = (Button)layout.findViewById(R.id.positive):
negative = (Button)layout.findViewById(R.id.negative):
positive.setVisibility(View.GONE);
negative.setVisibility(View.GONE);
}
public void setPositiveButton(String buttonText, View.OnClickListener listener) {
positive.setText(buttonText);
positive.setOnClickListener(listener);
positive.setVisibility(View.VISIBLE);
}
public void setNegativeButton(String buttonText, View.OnClickListener listener) {
negative.setText(buttonText);
negative.setOnClickListener(listener);
negative.setVisibility(View.VISIBLE);
}
}
Я бы сначала предложил попробовать setPositiveButton() и setNegativeButton(). –
@ Code-Guru Эти методы не существуют в классе Dialog. Дэвид, почему бы просто не использовать AlertDialog, а не воссоздать его? – Sam
@Sam Извините, сначала я должен был дважды проверить руководства API. Вы можете использовать AlertDialog вместо обычного диалога. Он имеет метод setButton(), который должен делать то, что вы хотите. –