删除 DialogFragment 的标题

Removing title of a DialogFragment

一段时间以来,我一直在尝试删除 DialogFragment 的标题,但几次尝试都失败了。我试过这些:

<style name="dialog" parent="@android:style/Theme.Holo.Dialog">
    <item name="android:windowNoTitle">true</item>
</style>

还有这个:

    int style, theme;

    style = DialogFragment.STYLE_NO_TITLE;
    theme = R.style.dialog;//Tried using Theme.Holo.Dialog here too


    setStyle(style, theme);//Setting theme to 0 renders it invisible. Content only

还有这个(没有效果):

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
     Dialog dialog = super.onCreateDialog(savedInstanceState);

     // request a window without the title
     dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
     return dialog;
}

None去除标题有效果

还有其他想法吗?

编辑:

DIalogFragment 中的重要代码:

public class MenuDialog extends DialogFragment implements View.OnClickListener {
    Context c;
    Clicker cl;
    Game game;

    public static MenuDialog newInstance() {
        MenuDialog f = new MenuDialog();

        // Supply num input as an argument.
        Bundle args = new Bundle();

        f.setArguments(args);

        return f;
    }

    public void params(Context c, Clicker cl, Game game){
        this.c = c;
        this.cl = cl;
        this.game = game;
    }




    @Override
    public void onCreate(Bundle sis){
        super.onCreate(sis);

        int style, theme;

        style = DialogFragment.STYLE_NO_TITLE;
        theme = R.style.dialog;//This theme is as defined above


        setStyle(style, theme);


    }

    private View v;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.menu, container, false);
        this.v = v;
        setButtons();
        return v;
    }

}

显示对话框:

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag("dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    MenuDialog newFragment = MenuDialog.newInstance();
    newFragment.params(getBaseContext(), clicker, this);
    newFragment.show(ft, "dialog");

正常创建对话框,并在显示前添加如下一行:

myDialog.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

编辑: 添加了 .getDialog() 调用

编辑 2:使用示例的 link 进行测试

我现在已经测试了这段代码并且它有效:

public class HelpDialog extends DialogFragment {

    public HelpDialog() {
        // Empty constructor required for DialogFragment
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //Inflate the XML view for the help dialog fragment
        View view = inflater.inflate(R.my_layout, container);

        HelpDialog.this.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);


        return view;
    }

}

我这样称呼对话框:

HelpDialog dialog = new HelpDialog(); dialog.show(getFragmentManager(),"test");