对话框布局双层错误透明背景 [英] Dialog layout double layered wrong transparant background
本文介绍了对话框布局双层错误透明背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public Builder createNewDialog(int type){
AlertDialog .Builder dlg = null;
switch(type){
case(1):
dlg = new AlertDialog.Builder(new ContextThemeWrapper(this,
R.style.CustomDialogTheme));
LayoutInflater inflater = this.getLayoutInflater();
dlg.setView(inflater.inflate(R.layout.dialognewplayer,null))
.setPositiveButton(Add Player,null).setNegativeButton(Cancel,null).create ();
break;
}
return dlg;
}
// styles.xml:
<?xml version =1.0encoding =utf-8?>
< resources>
< style name =AppThemeparent =android:Theme.Light>< / style>
< style name =CustomDialogThemeparent =android:Theme.Dialog>
< item name =android:windowBackground> @ color / transparent_color< / item>
< item name =android:windowIsFloating> false< / item>
< item name =android:windowNoTitle> true< / item>
< item name =android:background>#ffffff< / item>
< / style>
< / resources>
//和colors.xml
<?xml version =1.0encoding =utf-8?>
< resources>
< color name =transparent_color>#ffffff< / color>
< / resources>
但是,如图所示,弹出窗口有一些错误...似乎双层,第一层仍然有一个边框,透明的背景仍然是黑色的..我想我处理错误,但我没有看到它...
解决方案
使用透明主题,并使用android自己的透明色。
< style name =CustomDialogTheme parent =@ android:style / Theme.Translucent>
< item name =android:windowIsFloating> false< / item>
< item name =android:windowNoTitle> true< / item>
< item name =android:background> @android:color / transparent< / item>
< / style>
I want to make a white, no bordered, popup view. To accomplish this I use a custom dialog with a custom style:
public Builder createNewDialog(int type) {
AlertDialog.Builder dlg = null;
switch (type) {
case (1):
dlg = new AlertDialog.Builder(new ContextThemeWrapper(this,
R.style.CustomDialogTheme));
LayoutInflater inflater = this.getLayoutInflater();
dlg.setView(inflater.inflate(R.layout.dialognewplayer, null))
.setPositiveButton("Add Player", null).setNegativeButton("Cancel", null).create();
break;
}
return dlg;
}
//styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Light"></style>
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowBackground">@color/transparent_color</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">#ffffff</item>
</style>
</resources>
//and colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_color">#ffffff</color>
</resources>
However, as you can see at the image, the popup has some errors... it appears to be double layered with the first layer still having a border, and the transparant background is still black.. I think I am handling something wrong but I am not seeing it...
解决方案
Use the Translucent Theme and use android own transparent color.
<style name="CustomDialogTheme" parent="@android:style/Theme.Translucent">
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
</style>
这篇关于对话框布局双层错误透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文