以下是对话框声明的代码:
final Dialog dialog = new Dialog(BookAppointmentActivity.this,R.style.TranslucentBlue );
//Dialog dialog = new Dialog(BookAppointmentActivity.this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen );
dialog.setContentView(R.layout.customedialog);
Window window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();
这是我的style.xml
<color name="transparent_green_color">@color/dialog_back</color>
<style name="TranslucentBlue" parent="android:Theme.Translucent">
<item name="android:windowBackground">@color/transparent_green_color</item>
</style>
答案 0 :(得分:3)
好的,我得到了解决方案
首先在主题中进行更改。
不要以客户为主题。使用android.R.style.Theme_Translucent_NoTitleBar_Fullscreen
final Dialog dialog = new Dialog(BookAppointmentActivity.this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
而不是自定义主题,并添加以下内容:
window.setBackgroundDrawableResource(R.color.dialog_back);
完整代码:
final Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.customedialog);
Window window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
window.setBackgroundDrawableResource(R.color.dialog_back);
dialog.show();
使用资源文件color.xml
中的颜色,最后但并非最不重要的是,不要忘记降低颜色的不透明度。