3 回答
TA贡献1786条经验 获得超11个赞
在清单中设置主题通常用于Activity。
如果要设置Theme for Fragment,请在Fragment的onCreateView()中添加下一个代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// create ContextThemeWrapper from the original Activity Context with the custom theme
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.yourCustomTheme);
// clone the inflater using the ContextThemeWrapper
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
// inflate the layout using the cloned inflater, not default inflater
return localInflater.inflate(R.layout.yourLayout, container, false);
}
- 3 回答
- 0 关注
- 383 浏览
添加回答
举报