<style name="AlertDialog" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
<!-- 这里设置背景为透明,为了隐藏边框 -->
<item name="android:windowBackground">@color/text_color_white</item>
<item name="android:windowNoTitle">true</item>
<!-- 这里是修改顶部标题背景颜色,具体颜色自己定,可以是图片 -->
<item name="android:topDark">@color/text_color_white</item>
<!-- 这里是修改内容区域背景颜色 -->
<item name="android:centerDark">@color/text_color_white</item>
<item name="android:windowAnimationStyle">@android:color/transparent</item>
</style>
AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.AlertDialog);
builder.setTitle("选择性别");
String[] items = {"男", "女"};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sexChoose.chooseSex(which);
}
});
builder.show();
本来代码是这样的,结果效果是这样的。
查了又查,改了又改,没办法。最后想把自己添加的效果全去掉,变成了这样。
<style name="AlertDialog" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
</style>
然后就恢复正常了
最后经过排查 是这一项的原因,添上就出现黑背景,去掉就正常了。
<item name="android:windowBackground">@color/text_color_white</item>
我在另外一个项目里面这样用是没有问题的,但是在这个项目出了问题,比较两个项目activity使用的主题后,没有发现有什么不同
猜测可能是项目里面用的jar或者其他什么原因,猜不透。。。
如果不懂,就从最开始一点来。可能效果会更好。