15

如何在淡化背景的对话框周围移除这个“shadowBox”效果?

我知道我可以创建完全自定义的视图,但假设我想保持简单。我有只有 textView 和 2 个按钮的对话框的 xml 布局,我只想为这个对话框停止淡入淡出。

4

5 回答 5

45

尝试:

dialog.getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND);
于 2011-08-21T16:07:35.087 回答
9

style.xml在里面创建values并放置如下内容:

<?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>

最后,将此样式放入您的对话框中。

于 2011-01-21T10:25:04.513 回答
6

只需使用

 dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
于 2015-09-06T14:06:02.670 回答
2

这里给出示例类

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>
于 2011-01-21T10:44:38.257 回答
0

只是你知道也可以通过在你的主题中写下这个来改变暗淡的数量:

<item name="android:backgroundDimAmount">0.5</item>
于 2018-04-03T14:56:37.497 回答