问题描述
就像是开发人员指南中所描述我创建了一个自定义的DialogFragment。
现在,我试图做听起来很简单,但我不能得到它的工作。
我已经定义:的android:背景=@机器人:彩色/透明
在我的布局XML至极我加载像这样(在我的onCreateDialog):
I have created a custom DialogFragment like it is described in the developer guide. Now what i am trying to do sounds simple enough, but i cannot get it to work.I have defined: android:background="@android:color/transparent"
in my layout xml wich i am loading like this (in my onCreateDialog):
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.pausedialog, null);
setStyle(STYLE_NO_FRAME, R.style.CustomDialog);
正如你可以看到我也试图设置自定义样式在DialogFragment至极的定义是这样的:
As you can see i also tried to set a custom style in the DialogFragment wich is defined like this:
<style name="CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:alwaysDrawnWithCache">false</item>
<item name="android:windowContentOverlay">@null</item>
</style>
我也试过 getDialog()getWindow()setBackgroundDrawable(新ColorDrawable(0));
这导致空指针异常。
And i also tried getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));
which leads to a null pointer exception.
我使用 android.support.v4.app.DialogFragment
。可这是原因?
还是我在做别的事情了?
I am using android.support.v4.app.DialogFragment
. Can this be the cause?Or am i doing something else wrong?
如果您需要在对话框的截图,请让我知道!
谢谢
If you need a screenshot of the dialog please let me know!Thanks
推荐答案
尝试设置的风格和主题在你的dialogFragment类实现的onCreate方法。
Try to set style and theme in onCreate method of your dialogFragment class implementation.
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
int style=DialogFragment.STYLE_NO_TITLE;
int theme=android.R.style.Theme_Translucent;
setStyle(style, theme);
}
或者
如果您正在使用Dialog类,那么你还可以设置样式和主题对话实例。
if you are using Dialog class then you can also set Style and theme on dialog instance.
这篇关于不能让我的DialogFragment背景是透明的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!