Android4: 动态切换界面风格
2012-02-11 15:16
316 查看
Theme.Light:
Theme.Dark:
1. styles.xml定义两套theme
2. 点击Day/Night时
3. theme id 保存为savedInstanceState
4. onCreate中根据theme id 加载theme
Theme.Dark:
1. styles.xml定义两套theme
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme.Light" parent="@android:style/Theme.Holo.Light"> <item name="menuIconToggleTitle">@drawable/ic_menu_toggle_title_holo_light</item> <item name="menuIconToggleTheme">@drawable/ic_menu_toggle_theme_holo_light</item> </style> <style name="AppTheme.Dark" parent="@android:style/Theme.Holo"> <item name="menuIconToggleTitle">@drawable/ic_menu_toggle_title_holo_dark</item> <item name="menuIconToggleTheme">@drawable/ic_menu_toggle_theme_holo_dark</item> </style> </resources>
2. 点击Day/Night时
case R.id.menu_toggleTheme: if (mThemeId == R.style.AppTheme_Dark) { mThemeId = R.style.AppTheme_Light; } else { mThemeId = R.style.AppTheme_Dark; } this.recreate(); return true;
3. theme id 保存为savedInstanceState
@Override public void onSaveInstanceState (Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("theme", mThemeId); }
4. onCreate中根据theme id 加载theme
if(savedInstanceState != null) { if (savedInstanceState.getInt("theme", -1) != -1) { mThemeId = savedInstanceState.getInt("theme"); this.setTheme(mThemeId); } }
相关文章推荐
- android 局部界面动态切换
- android 局部界面动态切换
- android 局部界面动态切换
- Android 2.0后常用界面切换效果
- android界面切换
- Android 安卓 fragment+viewpager 仿qq界面 实现点击菜单切换界面+滑动切换viewpager切换界面
- android使用百度地图在切换界面的时候地图左下角Logo变成白色方块
- Android自动化测试中uiautomator修改uiautomatorviewer获取不到动态界面的缺陷
- 【译】Android主题动态切换开源库Prism基本原理3-搭配Palette使用
- Android--多页面管理控件之ViewFlipper实现子界面的自动切换
- Android 必知必会 - 动态切换着色模式和全屏模式
- (转) Android 全屏控制:动态切换全屏和非全屏
- Android 界面横竖屏切换 顶部状态栏(标题栏)显示与隐藏
- 谈谈自定义Android界面切换效果库的使用
- Android动态切换菜单
- Android UI设计 选项卡实现界面切换
- Android Activity界面切换添加动画特效
- Android中Fragment的动态加载和双屏切换问题
- java 界面换肤(切换风格)
- android-使用ViewGroup实现左右滑动切换界面以及界面裂开的效果