Reputation: 829
I have a requirement to create an AlertDialog
, which is split vertically into two zones:
The question is, is it possible to have anything like that or all alertDialogs have to have all their buttons at the bottom? I don't even know where to start. I've tried looking at AlertDialog
class, but could see anything suitable.
Upvotes: 2
Views: 15576
Reputation: 865
I'm afraid that I'm too late but a very simple solution would be:
Assuming you know either ways to set a button to an AlertDialog
, I'm gonna omit this part:
…
yourDialog.show();
Button btn = yourDialog.getButton(DialogInterface.BUTTON_NEUTRAL);//Whatever button it is.
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) btn.getLayoutParams();
params.topMargin = yourValue;//Enter your desired margin value here.
params.bottomMargin = yourValue;
params.leftMargin = yourValue;
params.rightMargin = yourValue;
btn.setLayoutParams(params);
Upvotes: 1
Reputation: 173
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity,
R.style.MyAlertDialogStyle);
builder.setTitle(mActivity.getResources().getString(R.string.app_name));
builder.setCancelable(false);
builder.setMessage(str_message);
builder.setPositiveButton(str_btn1,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (listener != null) {
listener.onClick(null);
}
}
});
if (str_btn2 != null) {
builder.setNegativeButton(str_btn2,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface,
int i) {
if (listener2 != null) {
listener2.onClick(null);
}
}
});
}
builder.show();
Edit : Please see the image above. You will get the output like this. Simply create a dialog style
Dialog Style in styles.xml
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <!-- Used for the buttons -->
<item name="android:textStyle">bold</item>
<item name="colorAccent">@android:color/holo_blue_bright</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">@android:color/black</item>
<!-- Used for the background -->
<item name="android:background">@android:color/white</item>
</style>
Upvotes: 3
Reputation: 14173
it looks like you don't need an AlertDialog
for this, but yes you can do it with AlertDialog
. create your view and then use AlertDialog.Builder
without calling setPositiveButton()
, setNegativeButton()
etc..
AlertDialog alertDialog = new AlertDialog.Builder(context)
.setView(yourContentView)
.create();
Upvotes: 2