问题描述
背景
我试图把一个层上会有说明当前屏幕上正在发生的事情,类似于发生的。
我知道有一些方案来解决这个(如showCase库和superToolTips库),我也知道我可以创建一个视图,并通过将其添加到活动的窗口设置在顶部,但我需要把上面整个对话层。
问题
无论我怎么努力,每一个解决方案不工作,我需要它的工作方式。
总之,我需要的是:
-
全屏对话框。
-
没有改变(不可视和不符合逻辑)的操作栏,通知栏和内容背后的活动,这意味着该对话框后面的一切都保持同样的它表明一个时刻是所示的对话框之前。
-
是透明的,除了我使用的对话框中,应正常显示的看法。
我已经试过
可悲的是,我一直得到的东西,我需要的只是一部分。
这是我的code:
styles.xml:
<样式名称=full_screen_dialog>
<项目名称=机器人:窗框> @空< /项目>
<项目名称=机器人:windowIsFloating>真< /项目>
<项目名称=机器人:windowContentOverlay> @空< /项目>
<项目名称=机器人:windowAnimationStyle> @android:款式/ Animation.Dialog< /项目>
<项目名称=机器人:windowSoftInputMode> stateUnspecified | adjustPan< /项目>
< /风格>
MainActivity.java:
...
最后一个对话框对话框=新的对话框(这一点,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();
这code将提上活动的顶部的布局,但遗憾的是它没有任何透明度,即使我已经将其设置。我用的布局很简单这就是为什么我不张贴。
quesiton
我在想什么?应该做些什么来解决这个code?
我怎样才能使对话双方透明,全屏幕,它不会改变操作栏和通知栏。
工作液
编辑:找到一个很好的解决方案后,这里的工作code:
@覆盖
保护无效的onCreate(最终捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
最后一个对话框对话框=新的对话框(本);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.floating_tutorial);
最后一个窗口窗口= dialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setBackgroundDrawable(新ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
只要改变你的对话框的背景颜色:
dialog.getWindow()setBackgroundDrawable(新ColorDrawable(Color.TRANSPARENT))。
编辑:
这prevents朦胧的效果:
dialog.getWindow()clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)。
background
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 .
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.
problem
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.
what i've tried
sadly, i've always got only a part of the things i needed.
here's my code:
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:
...
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.
quesiton
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.
Working solution
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);
这篇关于在活动之上创建一个透明的对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!