android -详谈Style和Theme

Android上的Style分为了两个方面:
1.Theme是针对窗体级别的,改变窗体样式
2.Style是针对窗体元素级别的,改变指定控件或者Layout的样式。
Android系统的themes.xml和style.xml(位于系统源代码frameworks\base\core\res\res\values\)包含了很多系统定义好的style
一些系统的Theme和Style 给出以下我学习的链接借鉴

如何新建自定义的风格和主题:
1.在res/values 目录下新建一个名叫style.xml的文件。增加一个<resources>根节点。
2.对每一个风格和主题,给<style>element增加一个全局唯一的名字,也可以选择增加一个父类属性。在后边我们可以用这个名字来应用风格,而父类属性标识了当前风格是继承于哪个风格。
3.在<style>元素内部,申明一个或者多个<item>,每一个<item>定义了一个名字属性,并且在元素内部定义了这个风格的值。
4.你可以应用在其他XML定义的资源。

风格
申明一个风格的实例:
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="Custom_Text" parent="@style/Text">
 <item name="android:textSize">18sp</item>
 <item name="android:textColor">#008</item>
 </style>
</resources>
引用风格
<EditText id="@+id/text1"
 style="@style/Custom_Text<span style="font-family: Arial;">"</span>
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="引用了风格Custom_Text" />

主题
申明一个主题的实例:
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="Custom_Theme">
 <item name="android:windowNoTitle">true</item>
 <item name="windowFrame">@drawable/screen_frame</item>
 <item name="windowBackground">@drawable/screen_background_white</item>
 <item name="panelForegroundColor">#FF000000</item>
 <item name="panelBackgroundColor">#FFFFFFFF</item>
 <item name="panelTextColor">?panelForegroundColor</item>
 <item name="panelTextSize">14</item>
 <item name="menuItemTextColor">?panelTextColor</item>
 <item name="menuItemTextSize">?panelTextSize</item>
 </style>
</resources>
引用主题(主题是不能应用在某一个单独的View里

1.在manifest当中设置主题

<application android:theme="@style/Custom_Theme">//应用全部
<activity android:theme="@android:style/Theme.Dialog">//应用某个activity,用对话框主题来让你的Activity看起来像一个对话框。
2.在程序当中设置主题
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 ...
 setTheme(android.R.style.Theme_Light);//用setTheme();方法 要在setContentView();之前
 setContentView(R.layout.linear_layout_3);
}
其他
   android:theme="@android:style/Theme.Dialog"   将一个Activity显示为对话框模式
   android:theme="@android:style/Theme.NoTitleBar"  不显示应用程序标题栏
   android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不显示应用程序标题栏,并全屏
   android:theme="@android:style/Theme.Light"  背景为白色
   android:theme="@android:style/Theme.Light.NoTitleBar"  白色背景并无标题栏 
   android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"  白色背景,无标题栏,全屏
   android:theme="@android:style/Theme.Black"  背景黑色
   android:theme="@android:style/Theme.Black.NoTitleBar"  黑色背景并无标题栏
   android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"    黑色背景,无标题栏,全屏
   android:theme="@android:style/Theme.Wallpaper"  用系统桌面为应用程序背景
   android:theme="@android:style/Theme.Wallpaper.NoTitleBar"  用系统桌面为应用程序背景,且无标题栏
   android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"  用系统桌面为应用程序背景,无标题栏,全屏
   android:theme="@android:style/Translucent"
   android:theme="@android:style/Theme.Translucent.NoTitleBar" 半透明,无标题
   android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" 半透明,无标题,全屏
   android:theme="@android:style/Theme.Panel" 面板风格显示
   android:theme="@android:style/Theme.Light.Panel" 平板风格显示



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值