我有一个要求,以创建一个AlertDialog
,它被垂直分割成两个区域:的Android AlertDialog按钮定位
- 其中一个区(右侧)的应有对话框按钮(确定,取消和设置)在这些按钮的顶部和另一个布局。
- 此对话框的左侧应该有另一个布局,比如图像。
问题是,是否有可能有类似的东西或所有的alertDialogs都必须在底部有所有的按钮?我甚至不知道从哪里开始。我试过看看AlertDialog
班,但可以看到任何合适的东西。
我有一个要求,以创建一个AlertDialog
,它被垂直分割成两个区域:的Android AlertDialog按钮定位
问题是,是否有可能有类似的东西或所有的alertDialogs都必须在底部有所有的按钮?我甚至不知道从哪里开始。我试过看看AlertDialog
班,但可以看到任何合适的东西。
它看起来像你不需要AlertDialog
这个,但是你可以用AlertDialog
来做到这一点。创建视图,然后使用AlertDialog.Builder
不调用setPositiveButton()
,setNegativeButton()
等。
AlertDialog alertDialog = new AlertDialog.Builder(context)
.setView(yourContentView)
.create();
谢谢,我认为,这是我需要的 – etilia
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();
编辑:请参见上面的图像。你会得到这样的输出。只需在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>
看看本作开始:http://stackoverflow.com/questions/13341560/how-to-create-a-custom -dialog-box-in-android – Zaki
也许[this SO question](http://stackoverflow.com/questions/18352324/how-can-can-i-add-custom-buttons-into-an-alertdialogs-layout)可以得到一些帮助 –
谢谢@Zaki。看起来像我可以尝试.. – etilia