Zoe*_*Zoe 2 android android-dialogfragment
我已经尝试了一段时间以删除DialogFragment的标题,但是几次尝试都失败了。我尝试了这些:
<style name="dialog" parent="@android:style/Theme.Holo.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
和这个:
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
Run Code Online (Sandbox Code Playgroud)
并且这(无效):
@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;
}
Run Code Online (Sandbox Code Playgroud)
没有任何作用会删除标题。
还有其他想法吗?
编辑:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
显示对话框:
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");
Run Code Online (Sandbox Code Playgroud)
通常创建对话框,并在显示之前添加如下一行:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我这样叫对话框:
HelpDialog dialog = new HelpDialog();
dialog.show(getFragmentManager(),"test");
| 归档时间: |
|
| 查看次数: |
1730 次 |
| 最近记录: |