Android学习笔记之Theme主题的修改设置
2015-01-16 16:20
459 查看
(1)布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<!-- 普通的样式使用方法 -->
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="31dp"
android:text="@string/hello_world" />
<!-- 自定义的样式使用方法 -->
<TextView
android:id="@+id/textView1"
style="@style/CodeFont.RED.BIG"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
style="@style/buttonStyle"
android:layout_alignLeft="@+id/textView2"
android:layout_centerVertical="true"
android:text="Button"
android:textColor="@color/textColor" />
</RelativeLayout>
(2)在values中新建xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:typeface">monospace</item>
</style>
<style name="CodeFont.RED">
<item name="android:textColor">#00FF00</item>
</style>
<style name="CodeFont.RED.BIG">
<item name="android:textSize">20sp</item>
</style>
<style name="buttonStyle">
<item name="android:textColor">#00FF00</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">48dp</item>
<item name="android:layout_marginLeft">148dp</item>
</style>
<color name="textColor">#ACBDEC</color>
<!-- 自定义主题 需要在清单文件中修改Android默认的主题 -->
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>
</resources>
(3)如果要修改Android默认的主题需要在清单文件中修改,下图圈出的位置就是需要修改的地方
(4)其他问阿金都可以默认无需修改!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<!-- 普通的样式使用方法 -->
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="31dp"
android:text="@string/hello_world" />
<!-- 自定义的样式使用方法 -->
<TextView
android:id="@+id/textView1"
style="@style/CodeFont.RED.BIG"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
style="@style/buttonStyle"
android:layout_alignLeft="@+id/textView2"
android:layout_centerVertical="true"
android:text="Button"
android:textColor="@color/textColor" />
</RelativeLayout>
(2)在values中新建xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:typeface">monospace</item>
</style>
<style name="CodeFont.RED">
<item name="android:textColor">#00FF00</item>
</style>
<style name="CodeFont.RED.BIG">
<item name="android:textSize">20sp</item>
</style>
<style name="buttonStyle">
<item name="android:textColor">#00FF00</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">48dp</item>
<item name="android:layout_marginLeft">148dp</item>
</style>
<color name="textColor">#ACBDEC</color>
<!-- 自定义主题 需要在清单文件中修改Android默认的主题 -->
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>
</resources>
(3)如果要修改Android默认的主题需要在清单文件中修改,下图圈出的位置就是需要修改的地方
(4)其他问阿金都可以默认无需修改!
相关文章推荐
- Android开发笔记之主题背景的修改(设置Theme.NoTitleBar后Activity背景变成黑色)
- XOOPS - theme主题风格 - 模板代码、区块设置与页面效果之间的对应关系
- 动态设置主题(Theme) 一些注意
- AndroidManifest.xml 中修改程序布局的 Theme 主题
- ggplot2作图详解:主题(theme)设置
- 设置漂亮的eclipse主题(Theme)风格
- ASP.NET: 为自定义控件设置主题(Theme)样式
- android之4.0的系统主题style修改android:Theme.Holo.Light
- Delphi程序的主题(Theme)设置
- 【android开发】修改主题theme(系统自带样式总结)
- Android学习笔记(十) 主题样式的设置
- RWT Theming in RAP(RAP主题Theme设置)
- android style(样式)和theme(主题)设置
- Flex中如何设置CheckBox标签(Label)与主题(theme )颜色的例子
- android style(样式)和theme(主题)设置
- XOOPS - theme主题风格 - 模板代码、区块设置与页面效果之间的对应关系
- gtk-theme-switch 设置GTK应用程序主题
- 怎样设置Win7个性化桌面图标不被主题修改
- Android style(样式)和theme(主题)设置
- android studio 修改主题设置