您的位置:首页 > 其它

fragment 中 切换主题

2017-03-11 16:21 405 查看
如果你的主题切换设置界面是写在fragment里边,只需要在改变了theme之后重新加载这个fragment就行了,代码如下:

@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

final Context contextThemeWrapper = new ContextThemeWrapper(
getActivity(), isDay ? R.style.day : R.style.night);
LayoutInflater localInflater = inflater
.cloneInContext(contextThemeWrapper);
View v = localInflater.inflate(R.layout.fragment_layout, container,
false);
return v;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: