Android-Styles and Themes
2015-12-08 12:46
841 查看
Android的样式和主题
Android的样式(styles) 比较简单 出发点也简单 就是可以重复利用一些属性
比如在xml文件里面多次用到某几个属性 可以将其声明为styles 然后应用 例子:
可以变成
<TextView
style="@style/CodeFont"
android:text="@string/hello" />这样好理解吧 就是将其抽取到一个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>
又分为继承自己的和继承Android系统的
Android系统如下:
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
继承自己定义的:
<style name="CodeFont.Red">
<item name="android:textColor">#FF0000</item>
</style>
有两种方式
1.是直接将style加到xml文件里面 正如上面所说的 这个仅仅是应用大那个view会有反应 其他比如他的字view是不会有任何反应的
2.强style或者themes应用到Activity,application上面去
那方法二是怎么应用的呢?比如
最后看看Android提供了哪些主题给我们
@android:style/Theme
@android:style/Theme.Black
@android:style/Theme.Black.NoTitleBar
@android:style/Theme.Black.NoTitleBar.Fullscreen
@android:style/Theme.DeviceDefault
@android:style/Theme.DeviceDefault.Dialog
@android:style/Theme.DeviceDefault.Dialog.Alert
@android:style/Theme.DeviceDefault.Dialog.MinWidth
@android:style/Theme.DeviceDefault.Dialog.NoActionBar
@android:style/Theme.DeviceDefault.Dialog.NoActionBar.MinWidth
@android:style/Theme.DeviceDefault.DialogWhenLarge
@android:style/Theme.DeviceDefault.DialogWhenLarge.NoActionBar
@android:style/Theme.DeviceDefault.InputMethod
@android:style/Theme.DeviceDefault.Light
@android:style/Theme.DeviceDefault.Light.DarkActionBar
@android:style/Theme.DeviceDefault.Light.Dialog
@android:style/Theme.DeviceDefault.Light.Dialog.Alert
@android:style/Theme.DeviceDefault.Light.Dialog.MinWidth
@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar
@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar.MinWidth
@android:style/Theme.DeviceDefault.Light.DialogWhenLarge
@android:style/Theme.DeviceDefault.Light.DialogWhenLarge.NoActionBar
@android:style/Theme.DeviceDefault.Light.NoActionBar
@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen
@android:style/Theme.DeviceDefault.Light.NoActionBar.Overscan
@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor
@android:style/Theme.DeviceDefault.Light.Panel
@android:style/Theme.DeviceDefault.NoActionBar
@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen
@android:style/Theme.DeviceDefault.NoActionBar.Overscan
@android:style/Theme.DeviceDefault.NoActionBar.TranslucentDecor
@android:style/Theme.DeviceDefault.Panel
@android:style/Theme.DeviceDefault.Settings
@android:style/Theme.DeviceDefault.Wallpaper
@android:style/Theme.DeviceDefault.Wallpaper.NoTitleBar
@android:style/Theme.Dialog
@android:style/Theme.Holo
@android:style/Theme.Holo.Dialog
@android:style/Theme.Holo.Dialog.MinWidth
@android:style/Theme.Holo.Dialog.NoActionBar
@android:style/Theme.Holo.Dialog.NoActionBar.MinWidth
@android:style/Theme.Holo.DialogWhenLarge
@android:style/Theme.Holo.DialogWhenLarge.NoActionBar
@android:style/Theme.Holo.InputMethod
@android:style/Theme.Holo.Light
@android:style/Theme.Holo.Light.DarkActionBar
@android:style/Theme.Holo.Light.Dialog
@android:style/Theme.Holo.Light.Dialog.MinWidth
@android:style/Theme.Holo.Light.Dialog.NoActionBar
@android:style/Theme.Holo.Light.Dialog.NoActionBar.MinWidth
@android:style/Theme.Holo.Light.DialogWhenLarge
@android:style/Theme.Holo.Light.DialogWhenLarge.NoActionBar
@android:style/Theme.Holo.Light.NoActionBar
@android:style/Theme.Holo.Light.NoActionBar.Fullscreen
@android:style/Theme.Holo.Light.NoActionBar.Overscan
@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor
@android:style/Theme.Holo.Light.Panel
@android:style/Theme.Holo.NoActionBar
@android:style/Theme.Holo.NoActionBar.Fullscreen
@android:style/Theme.Holo.NoActionBar.Overscan
@android:style/Theme.Holo.NoActionBar.TranslucentDecor
@android:style/Theme.Holo.Panel
@android:style/Theme.Holo.Wallpaper
@android:style/Theme.Holo.Wallpaper.NoTitleBar
@android:style/Theme.InputMethod
@android:style/Theme.Leanback.FormWizard
@android:style/Theme.Light
@android:style/Theme.Light.NoTitleBar
@android:style/Theme.Light.NoTitleBar.Fullscreen
@android:style/Theme.Light.Panel
@android:style/Theme.Light.WallpaperSettings
@android:style/Theme.Material
@android:style/Theme.Material.Dialog
@android:style/Theme.Material.Dialog.Alert
@android:style/Theme.Material.Dialog.MinWidth
@android:style/Theme.Material.Dialog.NoActionBar
@android:style/Theme.Material.Dialog.NoActionBar.MinWidth
@android:style/Theme.Material.Dialog.Presentation
@android:style/Theme.Material.DialogWhenLarge
@android:style/Theme.Material.DialogWhenLarge.NoActionBar
@android:style/Theme.Material.InputMethod
@android:style/Theme.Material.Light
@android:style/Theme.Material.Light.DarkActionBar
@android:style/Theme.Material.Light.Dialog
@android:style/Theme.Material.Light.Dialog.Alert
@android:style/Theme.Material.Light.Dialog.MinWidth
@android:style/Theme.Material.Light.Dialog.NoActionBar
@android:style/Theme.Material.Light.Dialog.NoActionBar.MinWidth
@android:style/Theme.Material.Light.Dialog.Presentation
@android:style/Theme.Material.Light.DialogWhenLarge
@android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar
@android:style/Theme.Material.Light.LightStatusBar
@android:style/Theme.Material.Light.NoActionBar
@android:style/Theme.Material.Light.NoActionBar.Fullscreen
@android:style/Theme.Material.Light.NoActionBar.Overscan
@android:style/Theme.Material.Light.NoActionBar.TranslucentDecor
@android:style/Theme.Material.Light.Panel
@android:style/Theme.Material.Light.Voice
@android:style/Theme.Material.NoActionBar
@android:style/Theme.Material.NoActionBar.Fullscreen
@android:style/Theme.Material.NoActionBar.Overscan
@android:style/Theme.Material.NoActionBar.TranslucentDecor
@android:style/Theme.Material.Panel
@android:style/Theme.Material.Settings
@android:style/Theme.Material.Voice
@android:style/Theme.Material.Wallpaper
@android:style/Theme.Material.Wallpaper.NoTitleBar
@android:style/Theme.NoDisplay
@android:style/Theme.NoTitleBar
@android:style/Theme.NoTitleBar.Fullscreen
@android:style/Theme.NoTitleBar.OverlayActionModes
@android:style/Theme.Panel
@android:style/Theme.Translucent
@android:style/Theme.Translucent.NoTitleBar
@android:style/Theme.Translucent.NoTitleBar.Fullscreen
@android:style/Theme.Wallpaper
@android:style/Theme.Wallpaper.NoTitleBar
@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen
@android:style/Theme.WallpaperSettings
@android:style/Theme.WithActionBar
@style/AppTheme
@style/Platform.AppCompat
@style/Platform.AppCompat.Light
@style/Platform.V11.AppCompat
@style/Platform.V11.AppCompat.Light
@style/Platform.V14.AppCompat
@style/Platform.V14.AppCompat.Light
@style/Theme.AppCompat
@style/Theme.AppCompat.Dialog
@style/Theme.AppCompat.Dialog.Alert
@style/Theme.AppCompat.Dialog.MinWidth
@style/Theme.AppCompat.DialogWhenLarge
@style/Theme.AppCompat.Light
@style/Theme.AppCompat.Light.DarkActionBar
@style/Theme.AppCompat.Light.Dialog
@style/Theme.AppCompat.Light.Dialog.Alert
@style/Theme.AppCompat.Light.Dialog.MinWidth
@style/Theme.AppCompat.Light.DialogWhenLarge
@style/Theme.AppCompat.Light.NoActionBar
@style/Theme.AppCompat.NoActionBar
追到源码分析 无非就是修改了以下几个属性达到的
具体属性实在是太多了 我有点混乱了 去百度一下看看
关键的有如下几个
1.首先决定是什么theme 有一个默认的themeAPPTheme
2.colorprimary actionbar的背景色 colorPrimaryDark 夜间的时候的背景色
Android的样式(styles) 比较简单 出发点也简单 就是可以重复利用一些属性
比如在xml文件里面多次用到某几个属性 可以将其声明为styles 然后应用 例子:
</pre><br /><pre name="code" class="html"><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#00FF00" android:typeface="monospace" android:text="@string/hello" />
可以变成
<TextView
style="@style/CodeFont"
android:text="@string/hello" />这样好理解吧 就是将其抽取到一个xml文件中
然后在
res/values/的styles.xml中声明CodeFont样式
<?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>
Inheritance
继承 styles是可以继承的又分为继承自己的和继承Android系统的
Android系统如下:
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
继承自己定义的:
<style name="CodeFont.Red">
<item name="android:textColor">#FF0000</item>
</style>
<style name="CodeFont.Red.Big"> <item name="android:textSize">30sp</item> </style>
Applying Styles and Themes to the UI
如何将styles和themes应用到UI上面去有两种方式
1.是直接将style加到xml文件里面 正如上面所说的 这个仅仅是应用大那个view会有反应 其他比如他的字view是不会有任何反应的
2.强style或者themes应用到Activity,application上面去
那方法二是怎么应用的呢?比如
<application android:theme="@style/CustomTheme">
<activity android:theme="@android:style/Theme.Dialog">
最后看看Android提供了哪些主题给我们
@android:style/Theme
@android:style/Theme.Black
@android:style/Theme.Black.NoTitleBar
@android:style/Theme.Black.NoTitleBar.Fullscreen
@android:style/Theme.DeviceDefault
@android:style/Theme.DeviceDefault.Dialog
@android:style/Theme.DeviceDefault.Dialog.Alert
@android:style/Theme.DeviceDefault.Dialog.MinWidth
@android:style/Theme.DeviceDefault.Dialog.NoActionBar
@android:style/Theme.DeviceDefault.Dialog.NoActionBar.MinWidth
@android:style/Theme.DeviceDefault.DialogWhenLarge
@android:style/Theme.DeviceDefault.DialogWhenLarge.NoActionBar
@android:style/Theme.DeviceDefault.InputMethod
@android:style/Theme.DeviceDefault.Light
@android:style/Theme.DeviceDefault.Light.DarkActionBar
@android:style/Theme.DeviceDefault.Light.Dialog
@android:style/Theme.DeviceDefault.Light.Dialog.Alert
@android:style/Theme.DeviceDefault.Light.Dialog.MinWidth
@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar
@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar.MinWidth
@android:style/Theme.DeviceDefault.Light.DialogWhenLarge
@android:style/Theme.DeviceDefault.Light.DialogWhenLarge.NoActionBar
@android:style/Theme.DeviceDefault.Light.NoActionBar
@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen
@android:style/Theme.DeviceDefault.Light.NoActionBar.Overscan
@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor
@android:style/Theme.DeviceDefault.Light.Panel
@android:style/Theme.DeviceDefault.NoActionBar
@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen
@android:style/Theme.DeviceDefault.NoActionBar.Overscan
@android:style/Theme.DeviceDefault.NoActionBar.TranslucentDecor
@android:style/Theme.DeviceDefault.Panel
@android:style/Theme.DeviceDefault.Settings
@android:style/Theme.DeviceDefault.Wallpaper
@android:style/Theme.DeviceDefault.Wallpaper.NoTitleBar
@android:style/Theme.Dialog
@android:style/Theme.Holo
@android:style/Theme.Holo.Dialog
@android:style/Theme.Holo.Dialog.MinWidth
@android:style/Theme.Holo.Dialog.NoActionBar
@android:style/Theme.Holo.Dialog.NoActionBar.MinWidth
@android:style/Theme.Holo.DialogWhenLarge
@android:style/Theme.Holo.DialogWhenLarge.NoActionBar
@android:style/Theme.Holo.InputMethod
@android:style/Theme.Holo.Light
@android:style/Theme.Holo.Light.DarkActionBar
@android:style/Theme.Holo.Light.Dialog
@android:style/Theme.Holo.Light.Dialog.MinWidth
@android:style/Theme.Holo.Light.Dialog.NoActionBar
@android:style/Theme.Holo.Light.Dialog.NoActionBar.MinWidth
@android:style/Theme.Holo.Light.DialogWhenLarge
@android:style/Theme.Holo.Light.DialogWhenLarge.NoActionBar
@android:style/Theme.Holo.Light.NoActionBar
@android:style/Theme.Holo.Light.NoActionBar.Fullscreen
@android:style/Theme.Holo.Light.NoActionBar.Overscan
@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor
@android:style/Theme.Holo.Light.Panel
@android:style/Theme.Holo.NoActionBar
@android:style/Theme.Holo.NoActionBar.Fullscreen
@android:style/Theme.Holo.NoActionBar.Overscan
@android:style/Theme.Holo.NoActionBar.TranslucentDecor
@android:style/Theme.Holo.Panel
@android:style/Theme.Holo.Wallpaper
@android:style/Theme.Holo.Wallpaper.NoTitleBar
@android:style/Theme.InputMethod
@android:style/Theme.Leanback.FormWizard
@android:style/Theme.Light
@android:style/Theme.Light.NoTitleBar
@android:style/Theme.Light.NoTitleBar.Fullscreen
@android:style/Theme.Light.Panel
@android:style/Theme.Light.WallpaperSettings
@android:style/Theme.Material
@android:style/Theme.Material.Dialog
@android:style/Theme.Material.Dialog.Alert
@android:style/Theme.Material.Dialog.MinWidth
@android:style/Theme.Material.Dialog.NoActionBar
@android:style/Theme.Material.Dialog.NoActionBar.MinWidth
@android:style/Theme.Material.Dialog.Presentation
@android:style/Theme.Material.DialogWhenLarge
@android:style/Theme.Material.DialogWhenLarge.NoActionBar
@android:style/Theme.Material.InputMethod
@android:style/Theme.Material.Light
@android:style/Theme.Material.Light.DarkActionBar
@android:style/Theme.Material.Light.Dialog
@android:style/Theme.Material.Light.Dialog.Alert
@android:style/Theme.Material.Light.Dialog.MinWidth
@android:style/Theme.Material.Light.Dialog.NoActionBar
@android:style/Theme.Material.Light.Dialog.NoActionBar.MinWidth
@android:style/Theme.Material.Light.Dialog.Presentation
@android:style/Theme.Material.Light.DialogWhenLarge
@android:style/Theme.Material.Light.DialogWhenLarge.NoActionBar
@android:style/Theme.Material.Light.LightStatusBar
@android:style/Theme.Material.Light.NoActionBar
@android:style/Theme.Material.Light.NoActionBar.Fullscreen
@android:style/Theme.Material.Light.NoActionBar.Overscan
@android:style/Theme.Material.Light.NoActionBar.TranslucentDecor
@android:style/Theme.Material.Light.Panel
@android:style/Theme.Material.Light.Voice
@android:style/Theme.Material.NoActionBar
@android:style/Theme.Material.NoActionBar.Fullscreen
@android:style/Theme.Material.NoActionBar.Overscan
@android:style/Theme.Material.NoActionBar.TranslucentDecor
@android:style/Theme.Material.Panel
@android:style/Theme.Material.Settings
@android:style/Theme.Material.Voice
@android:style/Theme.Material.Wallpaper
@android:style/Theme.Material.Wallpaper.NoTitleBar
@android:style/Theme.NoDisplay
@android:style/Theme.NoTitleBar
@android:style/Theme.NoTitleBar.Fullscreen
@android:style/Theme.NoTitleBar.OverlayActionModes
@android:style/Theme.Panel
@android:style/Theme.Translucent
@android:style/Theme.Translucent.NoTitleBar
@android:style/Theme.Translucent.NoTitleBar.Fullscreen
@android:style/Theme.Wallpaper
@android:style/Theme.Wallpaper.NoTitleBar
@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen
@android:style/Theme.WallpaperSettings
@android:style/Theme.WithActionBar
@style/AppTheme
@style/Platform.AppCompat
@style/Platform.AppCompat.Light
@style/Platform.V11.AppCompat
@style/Platform.V11.AppCompat.Light
@style/Platform.V14.AppCompat
@style/Platform.V14.AppCompat.Light
@style/Theme.AppCompat
@style/Theme.AppCompat.Dialog
@style/Theme.AppCompat.Dialog.Alert
@style/Theme.AppCompat.Dialog.MinWidth
@style/Theme.AppCompat.DialogWhenLarge
@style/Theme.AppCompat.Light
@style/Theme.AppCompat.Light.DarkActionBar
@style/Theme.AppCompat.Light.Dialog
@style/Theme.AppCompat.Light.Dialog.Alert
@style/Theme.AppCompat.Light.Dialog.MinWidth
@style/Theme.AppCompat.Light.DialogWhenLarge
@style/Theme.AppCompat.Light.NoActionBar
@style/Theme.AppCompat.NoActionBar
追到源码分析 无非就是修改了以下几个属性达到的
android:windowNoTitle 是否有title
windowFullscreen 是否全屏
colorBackground 颜色背景
<!-- Window colors -->
android:colorForeground 前景色
android:colorForegroundInverse 后景色
android:colorBackground 背景色
android:colorBackgroundCacheHint
android:disabledAlpha
android:backgroundDimAmount
android:windowBackground
<!-- Text colors -->
android:textColorPrimary
android:textColorPrimaryInverse
android:textColorSecondary
android:textColorSecondaryInverse
android:textColorTertiary
android:textColorTertiaryInverse
android:textColorPrimaryDisableOnly
android:textColorPrimaryInverseDisableOnly
android:textColorHint
android:textColorHintInverse
android:textColorHighlight
android:textColorLink
<!-- Text styles -->
android:textAppearance
android:textAppearanceInverse
android:textAppearanceLarge
android:textAppearanceLargeInverse
android:textAppearanceMedium
android:textAppearanceMediumInverse
android:textAppearanceSmall
android:textAppearanceSmallInverse
android:listChoiceIndicatorSingle
android:listChoiceIndicatorMultiple
具体属性实在是太多了 我有点混乱了 去百度一下看看
关键的有如下几个
1.首先决定是什么theme 有一个默认的themeAPPTheme
2.colorprimary actionbar的背景色 colorPrimaryDark 夜间的时候的背景色
相关文章推荐
- Android注解支持(Support Annotations)
- 浅谈Android系统启动过程
- 【Android自定义View】制作老虎机Android版
- Activity生命周期
- android焦点分发无法获取到Down事件,却有Move和Up
- Android 读取蓝牙设备信息开发
- AndroidStudio学习笔记一:了解Activity
- 从源码角度分析android事件分发处理机制
- Android Studio 简单介绍和使用问题小结
- Android ListView 设置选中item高亮状态
- Android Studio编码问题
- Jenkins构建Android项目持续集成之Jenkins的安装篇
- Android编译环境初始化浅析
- Android国外学习资源汇总(转)
- android轻量数据库SQLite的使用
- Android RecyclerView 使用完全解析 体验艺术般的控件
- android(cm11)状态栏源码分析(一)
- 分享Android开发自学笔记之AndroidStudio常用功能
- Android Studio 快捷键中英文对译
- Android ADB常用命令总结