卸下定制对话框黑色背景

我想删除自定义对话框黑色背景中所示的画面。 我敢肯定,黑色的背景是从对话框,而不是从应用程序的背景。

卸下定制对话框黑色背景

;

AlertDialog代码

public class MyAlertDialog extends AlertDialog { public MyAlertDialog(Context context) { super(context); } public MyAlertDialog(Context context, int theme) { super(context, theme); } }

活动代码

public void showMyDialogOK(Context context, String s, DialogInterface.OnClickListener OkListener) { MyAlertDialog myDialog = new MyAlertDialog(context, R.style.MyDialog2); myDialog.setTitle(null); myDialog.setMessage(s); myDialog.setButton(DialogInterface.BUTTON_POSITIVE ,"Ok", OkListener); myDialog.show(); }

样式

<?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen"> <item name="android:alertDialogStyle">@style/AlertDialog</item> </style> <style name="MyTheme2" parent="@android:style/Theme.Black"> <item name="android:alertDialogStyle">@style/AlertDialog</item> </style> <style name="AlertDialog"> <item name="android:fullDark">@null</item> <item name="android:fullBright">@null</item> <item name="android:topDark">@drawable/popup_top_dark</item> <item name="android:topBright">@null</item> <item name="android:centerBright">@null</item> <item name="android:centerDark">@drawable/popup_center_dark</item> <item name="android:centerMedium">@null</item> <item name="android:bottomDark">@null</item> <item name="android:bottomBright">@null</item> <item name="android:bottomMedium">@drawable/popup_bottom_medium</item> </style> <style name="MyDialog2" parent="@android:Theme.Dialog"> <item name="android:windowBackground">@null</item> <item name="android:buttonStyle">@style/CustomButton</item> </style> <style name="CustomButton" parent="@android:style/Widget.Button"> <item name="android:background">@drawable/button_stateful</item> </style> </resources>

图像资源

popup_center_dark.9.png

popup_bottom_medium.9.png

popup_top_dark.9.png

--------------解决方案-------------

public MyAlertDialog(Context context, int theme) extends AlertDialog {
super(context, theme);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
}

你可以像下面创建XML布局和设置对话框(dialog.xml)布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" style="@style/white_background_bl_aatharv">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true" android:id="@+id/instructions_view">

<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#FFFFFF"
android:text="text here " />
</LinearLayout>
</ScrollView>

这里是设置警告对话框布局的代码:

AlertDialog alert = cndtnsbuilder.create();
alert.setView(LayoutInflater.from(
currentactivity.this).inflate(
R.layout.dialog, null));
alert.show();

下面的方法为我工作:

getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Sonehow getWindow()。setBackgroundDrawable()并没有为我与AlertDialog工作。 我发现用对话更简单的解决方案。 这里是我的代码 -

final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.popup_window);
dialog.show();

您可以为您的对话框中设置样式。

<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.6</item>
</style>

试图对这个问题的几十个其他的解决方案后,什么结束了对我的工作是:

<style name="translucentDialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>

然后设置对话框我使用这个主题。

我删除我的自定义对话框的黑色背景的代码alertDialog.show()后:

try {
ViewGroup viewGroup1 = (ViewGroup) dialogView.getParent();
if (viewGroup1 != null) {
viewGroup1.setBackgroundResource(android.R.color.transparent);

ViewGroup viewGroup2 = (ViewGroup) viewGroup1.getParent();
if (viewGroup2 != null) {
viewGroup2.setBackgroundResource(android.R.color.transparent);
}
}
} catch (Exception e) {
}

分类:安卓 时间:2012-01-04 人气:206
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.819 (s). 9 q(s)