我一直试图删除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");
答案 0 :(得分:5)
正常创建对话框,并在显示之前添加如下所示的行:
myDialog.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
修改强>
添加了.getDialog()
电话
编辑2:使用示例
的链接进行测试我现在已经测试了这段代码并且它可以运行:
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;
}
}
我打电话给Dialog:
HelpDialog dialog = new HelpDialog();
dialog.show(getFragmentManager(),"test");