Android:对话框周围没有阴影
如何删除对话框周围使背景淡入淡出的“阴影盒”效果Android:对话框周围没有阴影,android,android-alertdialog,Android,Android Alertdialog,如何删除对话框周围使背景淡入淡出的“阴影盒”效果 我知道我可以创建完全自定义的视图,但我想保持它的简单。我有一个对话框的xml布局,只有文本视图和两个按钮,我只想为这一个对话框停止淡入淡出状态。创建样式。xml在值中并放置如下内容: <?xml version="1.0" encoding="utf-8"?> <resources> <style name="progress_dialog"> <item name="android:window
我知道我可以创建完全自定义的视图,但我想保持它的简单。我有一个对话框的xml布局,只有文本视图和两个按钮,我只想为这一个对话框停止淡入淡出状态。创建
样式。xml
在值中
并放置如下内容:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="progress_dialog">
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">#00ffffff</item>
</style>
真的
@空的
@空的
@android:style/Animation.Dialog
状态未指定|调整盘
假的
#00ffffff
最后,将此样式放到对话框中
这里给出示例类
public void showDialog () {
Dialog dialog = new Dialog(this);
Window window = dialog.getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
window.requestFeature(window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.sample);
ImageView imggameover, imgplayagain;
imggameover = (ImageView) dialog.findViewById(R.id.gameover);
imgplayagain = (ImageView) dialog.findViewById(R.id.playagain);
imgplayagain.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(getApplicationContext(), random.class));
onStop();
finish();
}
});
dialog.show();
}
对话框的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gameoverlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
>
<ImageView
android:id="@+id/gameover"
android:layout_width="225dip"
android:layout_height="160dip"
android:background="@drawable/gameover"
></ImageView>
<ImageView
android:id="@+id/playagain"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_marginLeft="100dip"
android:layout_marginTop="100dip"
android:background="@drawable/playagain"
></ImageView>
</RelativeLayout>
试试:
简单使用
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
您知道,也可以通过在主题中写入以下内容来更改暗量:
<item name="android:backgroundDimAmount">0.5</item>
0.5
有用的东西!但这并不能解决背景褪色的问题。它删除了对话框窗口:)Hm,将其作为style=“@style/styled_dialog”应用于my dialog.xml的linearLayout,而不使用任何内容。您使用的是哪个DialoBox?一个进步的?还是警报对话框?我在使用ProgressDialog时使用了它,并在实例化它时指定了样式。@Sheikh Aman我使用的是Alert dialog,但我找不到向其中添加样式的方法。谢谢。它起作用了。LayoutParams必须来自android.view.WindowManager对于targetSdkVersion=22不推荐使用此常量,这使得对话框的背景也变得透明。我想那不是我们想要的。
<item name="android:backgroundDimAmount">0.5</item>