我一直在尝试删除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;
}
都没有去除标题的效果。
还有其他想法吗?
编辑:
重要的代码在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");
我有同样的问题。解决'getDialog()。getWindow()。requestFeature(Window.FEATURE_NO_TITLE);'在'onViewCreated()' – tpk
添加onViewCreated:没有效果,没有崩溃 – Zoe
我使用onCreateDialog作为一个不同的SO问题。我添加了一些更多的代码片段。我在onCreateView中创建片段的内容 – Zoe