String[] taskName = new String[]{"测试1","测试2","测试3"};
AlertDialog.Builder builderTask = new AlertDialog.Builder(getView().getSelfActivity(), R.style.TransparentDialog);
builderTask.setCancelable(false);
builderTask.setIcon(R.mipmap.logo);
builderTask.setTitle("请选择使用属性");
builderTask.setSingleChoiceItems(taskName, check, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builderTask.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builderTask.setNeutralButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alertDialog = builderTask.create();
Window window = alertDialog.getWindow();
// 设置对话框的Window属性,不让其遮挡其他控件
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
WindowManager.LayoutParams lp = window.getAttributes();
//放置于底部
lp.gravity = Gravity.BOTTOM;
window.setAttributes(lp);
alertDialog.show();
在style中增加样式就可以了,可以自行按需修改
<!-- 弹框背景不遮挡-->
<style name="TransparentDialog" parent="Theme.AppCompat.Dialog.Alert">
<!-- 单选框选中时的颜色-->
<item name="colorAccent">@color/mainBackDrop</item>
<!-- 全部字体文字,标题加上按钮-->
<!-- <item name="android:textColor">@color/black</item>-->
<!-- 标题字体颜色-->
<item name="android:textColorPrimary">@color/black</item>
<!-- 弹框背景色-->
<item name="android:windowBackground">@color/white</item>
<!-- 单选圈圈颜色-->
<item name="android:textColorSecondary">@color/colorGray</item>
<!-- 单选字体颜色-->
<item name="textColorAlertDialogListItem">@color/black</item>
<!-- 背景不遮挡-->
<item name="android:backgroundDimEnabled">false</item>
</style>