如何设置DialogFragment的标题? [英] How to set the title of DialogFragment?
问题描述
这应该是一个简单的任务,但是由于某种原因,我可以找到一种方法来设置 DialogFragment . (我正在使用onCreateView
重载设置对话框的内容.)
This should be a simple task, but for some reason I can find a way to set the title of a DialogFragment. (I am setting the dialog contents using onCreateView
overload).
默认样式保留了标题的位置,但是我找不到DialogFragment
类上的任何方法来设置它.
The default style leaves a place for the title, but I can't find any method on the DialogFragment
class to set it.
使用onCreateDialog
方法设置内容时以某种方式神奇地设置了标题,所以我想知道这是设计使然,还是使用onCreateView
重载时设置它的特殊技巧.
The title is somehow magically set when the onCreateDialog
method is used to set the contents, so I wonder if this is by design, or there is a special trick to set it when using the onCreateView
overload.
推荐答案
您可以使用getDialog().setTitle("My Dialog Title")
就像这样:
public static class MyDialogFragment extends DialogFragment {
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Set title for this dialog
getDialog().setTitle("My Dialog Title");
View v = inflater.inflate(R.layout.mydialog, container, false);
// ...
return v;
}
// ...
}
这篇关于如何设置DialogFragment的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!