[英]Create a transparent dialog on top of activity
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 . 我试图在当前活动的基础上放置一个图层,该图层将解释当前屏幕上发生的情况,类似于contact + app上发生的情况。
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. 我知道有一些解决方案(比如showCase库和superToolTips库),我也知道我可以通过将它添加到活动窗口来创建视图并将其设置在顶部,但我需要放一个整体顶部的对话框层。
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. 可悲的是,我总是只得到我需要的一部分东西。
here's my code: 这是我的代码:
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. 如何使对话框既透明又全屏,并且不会更改操作栏和通知栏。
EDIT: 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();
}
Just change the background color of your Dialog: 只需更改对话框的背景颜色:
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Edit: 编辑:
This prevents the dim effect: 这可以防止暗淡效果:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Just add this, it really works! 只需添加它,它确实有效!
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowBackground">@android:drawable/alert_dark_frame</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.