【发布时间】:2016-07-14 18:46:39
【问题描述】:
我想在我的 DialogFragment 中自定义我的标题,我知道如何将标题设置为我的 DialogFragment ,但我想要的不仅仅是一个标题,我需要一个自定义的标题(颜色,字体大小......),所以我定义了一个 TextView 并自定义了它
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.height_fragment,container,false);
TextView title = new TextView(getContext());
title.setText("Your Height Information");
title.setGravity(Gravity.CENTER);
title.setTextSize(30);
title.setBackgroundColor(Color.GRAY);
title.setTextColor(Color.WHITE);
getDialog().setCustomTitle(title); //Error Can not resolve method setCustomTitle(android.widget.TextView)
return view;
}
但是这一行有错误
getDialog().setCustomTitle(title);
getDialog().setCustomTitle(title);
在发布此问题之前我进行了很多搜索,但我找不到如何自定义我的 DialogFragment 标题。 感谢您花时间帮助我
【问题讨论】:
-
您需要从布局中引用 TextView。我会在一秒钟内发布一些代码
-
你试过这个解决方案了吗? (stackoverflow.com/questions/28977576/…)
-
方法是getDialog().setTitle(String title)。 stackoverflow.com/questions/5193722/… google 上的第一个答案。
标签: java android android-fragments