关于Android的style和theme

来源:互联网 发布:北大青鸟软件培训中心 编辑:程序博客网 时间:2024/06/05 09:51

style是什么?

A style is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.
来自developer.android

翻译一下
style是指定视图或窗口的外观和格式属性的集合。样式可以指定诸如高度,填充,字体颜色,字体大小,背景颜色,以及更多的特性。style是在从指定布局XML单独的XML资源定义。

举个栗子

<?xml version="1.0" encoding="utf-8"?><resources><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:textColor">#00FF00</item><item name="android:typeface">monospace</item></style></resources>
<TextViewstyle="@style/CodeFont"android:text="@string/hello" />

style作用?

  • 设计与内容分开
  • 可继承
  • 便于统一风格

style如何书写?

↑↑↑看上面的栗子↑↑↑

关于继承系统的书写

<style name="CodeFont" parent="@android:style/TextAppearance.Medium">...</style>

关于继承自定义的书写

<style name="CodeFont1" parent="CodeFont">...</style>

关于继承系统theme的书写

<style name="LightThemeSelector" parent="android:Theme.Holo.Light">...</style><style name="LightThemeSelector" parent="@android:style/Theme.Holo.Light">...</style>

关于继承自定义theme的书写

<style name="LightThemeSelector" parent="@style/Theme.AppCompat">...</style>

style与theme的区别?

  • Theme是针对窗体级别的,改变窗体样式;
  • Style是针对窗体元素级别的,改变指定控件或者Layout的样式。

系统自带theme有哪些,如何使用?

android:theme=”@android:style/Theme.Dialog” : Activity显示为对话框模式
android:theme=”@android:style/Theme.NoTitleBar” : 不显示应用程序标题栏
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” : 不显示应用程序标题栏,并全屏
android:theme=”Theme.Light “: 背景为白色
android:theme=”Theme.Light.NoTitleBar” : 白色背景并无标题栏
android:theme=”Theme.Light.NoTitleBar.Fullscreen” : 白色背景,无标题栏,全屏
android:theme=”Theme.Black” : 背景黑色
android:theme=”Theme.Black.NoTitleBar” : 黑色背景并无标题栏
android:theme=”Theme.Black.NoTitleBar.Fullscreen” : 黑色背景,无标题栏,全屏
android:theme=”Theme.Wallpaper” : 用系统桌面为应用程序背景
android:theme=”Theme.Wallpaper.NoTitleBar” : 用系统桌面为应用程序背景,且无标题栏
android:theme=”Theme.Wallpaper.NoTitleBar.Fullscreen” : 用系统桌面为应用程序背景,无标题栏,全屏
android:theme=”Theme.Translucent : 透明背景
android:theme=”Theme.Translucent.NoTitleBar” : 透明背景并无标题
android:theme=”Theme.Translucent.NoTitleBar.Fullscreen” : 透明背景并无标题,全屏
android:theme=”Theme.Panel “: 面板风格显示
android:theme=”Theme.Light.Panel” : 平板风格显示

theme的一些属性

名称 作用 android:windowIsTranslucent 设置透明属性(防止启动时候的闪屏) android:windowBackground 设置背景图片 android:windowAnimationStyle Activity进入退出动画 android:windowNoTitle 不显示标题栏 android:textColor 默认字体颜色 android:windowFullscreen 是否全屏 android:windowIsFloating 是否浮现在activity之上 android:backgroundDimEnabled 背景是否模糊显示
0 0