android - 为应用程序实现不同的材料主题。基于材料设计的猫头鹰应用程序
问题描述
在此示例Material Design Owl 应用程序设计之后,有黄色主题的个性化屏幕、蓝色主题的浏览屏幕和深色主题的学习屏幕,如下所示:
我的问题是我应该为选定的屏幕实施 3 项活动吗?或者我应该为每个片段实现不同的主题?
我更喜欢一个带有喷气背包导航的活动,但是否可以为特定片段设置主题?
解决方案
在 manifest 中设置 Theme 通常用于 Activity。
如果要为 Fragment 设置 Theme,请在 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);
}
这将在 Activity 中使用经典片段进行。
推荐阅读
- matlab - 如何在 MATLAB 中以原始质量保存带有新绘制线条的图像
- c++ - 使用模板方法模拟类
- java - 具有多租户的单元测试 Grails 域类
- python - 如何在 Python 中捕获此错误消息“不被识别为内部命令”?
- db2 - DSNUTILB 使用 PRESORTED 选项
- mysql - 拉拉维尔。将 SQLite 上传到服务器(MySQL)
- python - 根据字典项目更改列表
- java - Firebase 身份验证的 SharedPreferences
- python - 如何遍历python中的类?(y金融类)
- lua - 大多数 mediawiki 模板的 Lua 错误 -129