android 主题 定制(1)
2013-12-30 18:20
363 查看
今天 想对自己的app做一个主题定制,就是可以动态修改应用的主题。
分为以下几个步骤:
1,首先,要实现动态的theme,因此要自定义属于自己的attr, 在values 中新建 attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="pageBackground" fromat="style"/>
<attr name="buttonStyle" fromat="style"/>
<attr name="headBackground" fromat="style"/>
<attr name="headBackButton" fromat="style"/>
</resources>
2,定义自己的theme,在values / style.xml 文件中加入:
<!-- 木质主题 -->
<style name="theme_xylon" parent="android:Theme.Light.NoTitleBar">
<item name="pageBackground">@style/xylon_back</item>
<item name="headBackground">@style/xylon_head</item>
<item name="headBackButton">@style/xylon_headback_button</item>
<item name="buttonStyle">@style/xylon_button</item>
</style>
<style name="xylon_back">
<item name="android:background">@drawable/xylon_bg</item>
</style>
<style name="xylon_button">
<item name="android:background">@drawable/xylon_btn_selector</item>
</style>
<style name="xylon_head">
<item name="android:background">@drawable/xylon_head_bg</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
</style>
<style name="xylon_headback_button">
<item name="android:background">@drawable/xylon_btn_rect</item>
</style>
3,布局中引用自己的 theme
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="?pageBackground">"等等,在需要自定义风格的地方 加上 style = "?attrName" ,这里啰嗦一句,关于 @ 和 ? 引用的区别:
@ 是之前定义了的资源,而? 是待代码动态定义的。
4,上面工作做好了后 在activity 创建之前 ,加载使用的theme,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.theme_xylon);
setContentView(R.layout.activity_cardio_test);
}
完工。
分为以下几个步骤:
1,首先,要实现动态的theme,因此要自定义属于自己的attr, 在values 中新建 attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="pageBackground" fromat="style"/>
<attr name="buttonStyle" fromat="style"/>
<attr name="headBackground" fromat="style"/>
<attr name="headBackButton" fromat="style"/>
</resources>
2,定义自己的theme,在values / style.xml 文件中加入:
<!-- 木质主题 -->
<style name="theme_xylon" parent="android:Theme.Light.NoTitleBar">
<item name="pageBackground">@style/xylon_back</item>
<item name="headBackground">@style/xylon_head</item>
<item name="headBackButton">@style/xylon_headback_button</item>
<item name="buttonStyle">@style/xylon_button</item>
</style>
<style name="xylon_back">
<item name="android:background">@drawable/xylon_bg</item>
</style>
<style name="xylon_button">
<item name="android:background">@drawable/xylon_btn_selector</item>
</style>
<style name="xylon_head">
<item name="android:background">@drawable/xylon_head_bg</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
</style>
<style name="xylon_headback_button">
<item name="android:background">@drawable/xylon_btn_rect</item>
</style>
3,布局中引用自己的 theme
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="?pageBackground">"等等,在需要自定义风格的地方 加上 style = "?attrName" ,这里啰嗦一句,关于 @ 和 ? 引用的区别:
@ 是之前定义了的资源,而? 是待代码动态定义的。
4,上面工作做好了后 在activity 创建之前 ,加载使用的theme,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.theme_xylon);
setContentView(R.layout.activity_cardio_test);
}
完工。
相关文章推荐
- Android主题定制及修改
- Android主题定制及修改
- Android 主题资源风格定制 <1>
- Android主题定制
- android Launcher3中定制第三方apk图标,实现类似主题功能
- Android recipe 定制窗口主题(window theme)
- android Launcher3中定制第三方apk图标,实现类似主题功能
- Android 5.0 Launcher客制化定制之 主题选择器
- Android 5.0 Launcher客制化定制之 主题包协议(MIUI主题、乐蛙主题兼容)
- Android开发 关于避免切换主题时免闪屏的几种方式
- Android 主题框架 ColorTheme
- Android定制属于你自己的导航栏
- Android-风格和主题
- 【Android】统一主题风格
- 定制android桌面系统
- android的样式(style)与主题(theme)
- Android主题切换之探究白天和夜间模式
- 定制Android设备的关机对话框
- 对android rotation的添加与定制
- Android中定制自己的Camera