在活动之上创建一个透明对话框 [英] Create a transparent dialog on top of activity

查看:30
本文介绍了在活动之上创建一个透明对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在当前活动的顶部放置一个图层,该图层可以解释当前屏幕上发生的情况,类似于 contact+ 应用程序 .

I'm trying to put a layer on top of the current activity which would have explanation of what is going on on the current screen, similar to what occurs on contact+ app .

我知道有一些解决方案(例如 showCase 库 和 superToolTips 库),我也知道我可以创建一个视图并通过将其添加到活动的窗口将其设置在顶部,但我需要将整个对话框层放在顶部.

I know there are some solutions for this (like the showCase library and the superToolTips library ) , and I also know that I can create a view and set it on top by adding it to the window of the activity , but I need put a whole dialog layer on top.

无论我尝试什么,每个解决方案都无法按照我需要的方式工作.

No matter what I try, each solution doesn't work the way I need it to work.

简而言之,我需要的是:

in short , what I need is:

  • 全屏对话框.

  • full screen dialog.

操作栏、通知栏和后面活动的内容没有变化(不是视觉上的,也不是逻辑上的),这意味着对话框后面的所有内容都与显示对话框之前显示的内容保持一致.

no change (not visual and not logical) to the action bar, notification bar, and content of the activity behind, meaning that everything behind the dialog stays the same it was shown a moment before the dialog was shown.

除了我用于对话框的视图外,应该是透明的,应该正常显示.

be transparent except for the views I use for the dialog, which should be shown normally.

可悲的是,我总是只得到我需要的一部分.

Sadly, I've always got only a part of the things I needed.

这是我的代码:

styles.xml:

styles.xml:

<style name="full_screen_dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    </style>

MainActivity.java:

MainActivity.java:

...
final Dialog dialog = new Dialog(this, R.style.full_screen_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.floating_tutorial);
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
dialog.getWindow().setFormat(PixelFormat.TRANSLUCENT);
dialog.show();

这段代码会将布局放在活动的顶部,但遗憾的是它没有任何透明度,即使我已经设置了它.我使用的布局非常简单,所以我不发布它.

This code will put the layout on top of the activity, but sadly it doesn't have any transparency , even though I've set it . The layout I've used is very simple which is why I don't post it.

我错过了什么?应该怎么做才能修复代码?

what am I missing ? what should be done to fix the code?

如何使对话框既透明、全屏又不会更改操作栏和通知栏.

how can I make the dialog both transparent, full screen AND that it won't change the action bar and notifications bar.

找到一个好的解决方案后,这里是工作代码:

after finding a good solution, here's the working code:

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.floating_tutorial);
    final Window window = dialog.getWindow();
    window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.show();
}

推荐答案

只需更改 Dialog 的背景颜色即可:

Just change the background color of your Dialog:

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

这可以防止暗淡效果:

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

这篇关于在活动之上创建一个透明对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆