Android 用户切换APP主题
来源:互联网 发布:国产镜头 知乎 编辑:程序博客网 时间:2024/05/16 14:15
准备两套 style,要求参数item标签完全相同,标签值可以更改。
<style name="SwitchTheme1" parent="@android:style/Theme.Black"> <item name="colorValue">#FF00FF00</item> <item name="floatValue">0.35</item> <item name="integerValue">33</item> <item name="booleanValue">true</item> <item name="dimensionValue">76dp</item> <!-- 如果string类型不是填的引用而是直接放一个字符串,在布局文件中使用正常,但代码里获取的就有问题 --> <item name="stringValue">@string/hello_world</item> <item name="referenceValue">@drawable/hand</item> </style> <style name="SwitchTheme2" parent="@android:style/Theme.Wallpaper"> <item name="colorValue">#FFFFFF00</item> <item name="floatValue">1.44</item> <item name="integerValue">55</item> <item name="booleanValue">false</item> <item name="dimensionValue">76px</item> <item name="stringValue">@string/action_settings</item> <item name="referenceValue">@drawable/ic_launcher</item> </style>
每个需要不同的主题样式引用,修改 attr.xml 或者创建新的 resource 文件,attr 自定义属性
<?xml version="1.0" encoding="utf-8"?> <resources> <attr name="colorValue" format="color" /> <attr name="floatValue" format="float" /> <attr name="integerValue" format="integer" /> <attr name="booleanValue" format="boolean" /> <attr name="dimensionValue" format="dimension" /> <attr name="stringValue" format="string" /> <attr name="referenceValue" format="reference" /> </resources>
引用时使用 ?attr/自定义属性名
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="?attr/referenceValue" />
因为 setTheme 方法只在当前 Activity有效,所以如果要整体更改,需要将 setTheme 方法 放在 BaseActivity 中
setTheme(R.style.MyAppTheme);setContentView(R.layout.main_activity);
切换主题
// 结束当前finish();// 重新打开Intent intent = getIntent();startActivity(intent);// 关闭界面切换动画overridePendingTransition(0,0);
此时如果返回之前的界面,主题修改不会起效,建议
singTask 模式 启动 MainActivity
阅读全文
0 0
- Android 用户切换APP主题
- Android app主题切换
- 不闪屏切换Android App主题
- app 主题切换
- Android实现app主题动态切换的两种方式
- 关于android动态切换app主题颜色方案
- Android App切换主题的实现原理剖析
- Android 实现切换主题皮肤功能(类似于众多app中的 夜间模式,主题包等)
- Android 实现切换主题皮肤功能(类似于众多app中的 夜间模式,主题包等)
- Android 实现切换主题皮肤功能(类似于众多app中的 夜间模式,主题包等)
- Android 把项目从App主题切换到AppCompat主题所碰到的一些问题
- Android动态切换主题
- Android动态切换主题
- Android 应用主题切换
- Android主题切换方案
- Android动态切换主题
- Android动态切换主题
- android 切换主题
- java三大特性值封装
- 打印机连接
- OpenCV2.4.13+VS2012开发环境配置
- w3af笔记
- 直接双击启动tomcat中的startup.bat闪退原因及解决方法
- Android 用户切换APP主题
- Linux学习第十五章--文件系统的操作
- Logback 配置说明
- 1005. 最大和
- 曾经被微信打得溃不成军的米聊现在活得还好么
- HRBUST
- 根据自身所在经纬度,查询周围一定范围内的地理位置(经纬度)
- html5-表单
- gets_s不能输入的问题