我需要创建一个AlertDialog
,它垂直分为两个区域:
- 其中一个区域(右侧)的底部应有对话框按钮(确定、取消和设置),而这些按钮的顶部应有另一种布局。
- 此对话框的左侧应该有另一个布局,例如图像。
问题是,是否有可能有类似的东西,或者所有警报对话框都必须将所有按钮放在底部?我什至不知道从哪里开始。我尝试查看 AlertDialog
类,但可以看到任何合适的内容。
最佳答案
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>
关于Android AlertDialog按钮定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38570266/