具有清晰背景的 DialogFragment(未变暗) [英] DialogFragment with clear background (not dimmed)
问题描述
我试图让 DialogFragment
的背景完全清晰.
I'm trying to get the background of a DialogFragment
to be completely clear.
将样式项 android:windowIsFloating
设置为 true(默认值),DialogFragment
完全按照我想要的方式显示,但背景非常暗.
With setting the style item android:windowIsFloating
to true (the default),
the DialogFragment
displays exactly how I want it to, but has a very dimmed background.
通过将 android:windowIsFloating
设置为 false,我得到了我想要的清晰背景,但是 DialogFragment 会炸毁大约 95% 的屏幕,在它周围只留下一个很小的间隙,您可以在那里看到它覆盖的视图.
By setting android:windowIsFloating
to false, I get the clear background I want, but the DialogFragment blows up to about 95% of the screen,
leaving only a tiny gap around it where you can see through to the view it overlays.
我已经尝试了大量的调整,但似乎无法覆盖这种行为.
I've tried ton's of tweaks and cannot seem to override this behavior.
是否需要使用PopupWindow
来达到想要的效果,或者有什么风格我可以覆盖的项目?
Do I need to use a PopupWindow
to achieve the desired effects, or are there some style
items that I can override ?
推荐答案
对我有用的是调整 onStart()
中的 WinowManager.LayoutParams
href="http://developer.android.com/reference/android/app/DialogFragment.html">DialogFragment:
What works for me is to adjust the WinowManager.LayoutParams
in onStart()
of the DialogFragment:
@Override public void onStart() {
super.onStart();
Window window = getDialog().getWindow();
WindowManager.LayoutParams windowParams = window.getAttributes();
windowParams.dimAmount = 0.90f;
windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(windowParams);
}
这篇关于具有清晰背景的 DialogFragment(未变暗)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!