問題描述
我正在嘗試在當前活動的頂部放置一個圖層,該圖層可以解釋當前屏幕上發生的情況,類似于 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);
這篇關于在活動之上創建一個透明對話框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!