android 主题和样式-style和Theme的区别和使用
来源:互联网 发布:明礼仪知荣辱演讲稿 编辑:程序博客网 时间:2024/04/24 00:07
项目中经常使用style和Theme,但却从来没有考虑过它们的区别,只会copy来copy去的,有时候还有些迷茫,为了彻底告别迷茫,现把这两者的区别和使用总结出来,供自己和大伙参考
一.作用域
Theme是针对窗体级别的,改变窗体样式。
Style是针对窗体元素级别的,改变指定控件或者Layout的样式
二.使用方式
Theme
1. 在res\values\ 下创建themes.xml或者styles.xml文件
2. 添加<resouces>节点(根节点)
3. 添加自定义的style
4.(1)在AndroidManifest.xml文件中,为Activity指定theme属性(推荐)
(2)Activity创建时调用setTheme函数 (必须在setContentView前调用 )
<style name="MyBubbleTheme" parent="@android:style/Theme.Dialog" ><item name="android:windowBackground">@drawable/bubble</item></style>
<activity android:name=".BlurThemeActivity" android:theme="@style/MyBubbleTheme" />
5.系统自带的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" //用系统桌面为应用程序背景,无标题栏,全屏
6.常用属性
<item name="windowBackground">@android:drawable/screen_background_dark</item> <item name="windowFrame">@null</item> <item name="windowNoTitle">false</item> <item name="windowFullscreen">false</item> <item name="windowIsFloating">false</item> <item name="windowContentOverlay">@android:drawable/title_bar_shadow</item> <item name="windowTitleStyle">@android:style/WindowTitle</item> <item name="windowTitleSize">25dip</item> <item name="windowTitleBackgroundStyle">@android:style/WindowTitleBackground</item> <item name="android:windowAnimationStyle">@android:style/Animation.Activity</item>
style
1. 在res\values\ 下创建styles.xml文件
2. 添加<resouces>节点(根节点)
3. 添加自定义的style
4.在特定控件或layout中添加style属性
<style name="MyTextStyle"> <item name="android:textColor">#FF0000C0</item> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style>
<TextView style="@style/MyTextStyle" />
很多程序刚启动的时候的Tips界面,气泡窗口和毛玻璃效果
代码如下:
BlurThemeActivity.java
import android.app.Activity;import android.os.Bundle;import android.view.WindowManager;public class BlurThemeActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Have the system blur any windows behind this one. getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); }}
themes.xml
<style name="MyBubbleTheme" parent="@android:style/Theme.Dialog" > <item name="android:windowBackground">@drawable/bubble</item> <item name="android:windowNoTitle">true</item> </style>
AndroidManifest.xml
<activity android:name=".BlurThemeActivity" android:theme="@style/MyBubbleTheme" />
0 0
- android 主题和样式-style和Theme的区别和使用
- Android中样式style和主题Theme的使用总结
- android基础---样式和主题(style&theme)
- Android中的主题(theme)和样式(style)
- Android样式和主题(style&theme)
- android style(样式)和theme(主题)设置
- android样式和主题(style&theme)
- Android样式和主题(style&theme)
- android-样式和主题(style&theme)
- android style(样式)和theme(主题)设置
- android style(样式)和theme(主题)设置
- Android style(样式)和theme(主题)设置
- Android 样式和主题(style&theme)
- Android 样式和主题(style&theme)
- Android样式(style)和主题(theme)
- Android主题theme和样式style总结
- Android style/theme (样式和主题)
- android样式和主题(style&theme)
- ELMAH--Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components 77 out of 90 rated th
- 阿里巴巴集团全资收购UC优视
- twitter storm源码走读之8 -- TridentTopology创建过程详解 - 徽沪一郎
- Ubuntu 下的sqlmap,nmap,metasploit安装
- 判断system()执行shell脚本是否正常执行结束
- android 主题和样式-style和Theme的区别和使用
- VC++ ado连接数据库(可以在VC6.0使用,以access数据库为实例)(1)
- 读书笔记 --- 接近传感器
- Linux文件默认权限
- XMPP协议内容和格式
- 驾驭工作的两大“法宝”:时间管理和好心态
- 如果你不想在IT行业被替代,扮演好这7个角色之一
- 黑马程序员_循环控制与break continue总结
- LDO线性电压调节器