Android中Theme和style介绍

来源:互联网 发布:威客网络赚钱平台 编辑:程序博客网 时间:2024/06/06 09:46

在android开发中可以使用系统为我们提供的主题样式来设置我们的应用主题风格,我们也可以自定义主题,可以在style.xml文件中自定义如下:

<resources>    <!-- 定义应用程序主题,该主题继承自系统主题:android:Theme.Light -->    <style name="AppBaseTheme" parent="android:Theme.Light">            </style>    <!-- Application theme.应用主题,继承自上面定义的主题:AppBaseTheme -->    <style name="AppTheme" parent="AppBaseTheme">        <!-- All customizations that are NOT specific to a particular API-level can go here. -->    </style></resources>

在主题定义中通过<style></style>来声明主题或样式名称,以及该父类定义的样式,这点跟css中的样式设置很类似。可以有两种方式来定义上面的继承关系:

第一种就是上面的xml中显示的,通过style的parent属性来指定父类样式。

第二种类似与css的样式继承方式:

<!-- 定义公共父类文本样式 -->    <style name="CommonTextStyle">        <item name="android:textColor">#000000</item>        <item name="android:textStyle">bold</item>    </style>    <!-- 定义标题文本样式,继承自上面的 CommonTextStyle-->    <style name="CommonTextStyle.titleStyle">        <item name="android:textColor">#cccccc</item>        <item name="android:textSize">18sp</item>        <item name="android:layout_width">wrap_content</item>        <item name="android:layout_height">wrap_content</item>    </style>

在androidSDK的data\res\values\themes.xml中定义着android系统中的各种主题样式,主要样式简介:

  1. <style name="Theme"> android最顶级父主题,其中包含了Text styles、Button styles、Gallery attributes、Window attributes、Dialog attributes、Toast attributes、Scrollbar attributes等等很多组件的基本样式的定义。
  2. <style name="Theme.NoTitleBar"> NoTitleBar主题继承顶级主题,并定义窗体没有标题栏:<item name="android:windowNoTitle">true</item>
  3. <style name="Theme.NoTitleBar.Fullscreen">无标题、填充整个屏幕主题:<item name="android:windowFullscreen">true</item><item name="android:windowContentOverlay">@null</item>
  4. <style name="Theme.Light">白色主题风格
  5. <style name="Theme.Light.NoTitleBar">白色无标题栏主题
  6. <style name="Theme.Light.NoTitleBar.Fullscreen">白色、无标题栏、填充屏幕主题
  7. <style name="Theme.Black">黑色主题风格
  8. <style name="Theme.Black.NoTitleBar">黑色无标题栏主题
  9. <style name="Theme.Black.NoTitleBar.Fullscreen">黑色、无标题栏、填充屏幕主题
  10. <style name="Theme.Wallpaper">壁纸主题
  11. <style name="Theme.Wallpaper.NoTitleBar">无标题壁纸主题
  12. <style name="Theme.Wallpaper.NoTitleBar.Fullscreen">无标题、填充屏幕主题
  13. <style name="Theme.Translucent">半透明主题
  14. <style name="Theme.Translucent.NoTitleBar">半透明、无标题栏主题
  15. <style name="Theme.Translucent.NoTitleBar.Fullscreen">半透明、无标题栏、填充屏幕主题
  16. <style name="Theme.Dialog">对话框主题

等等主题,还有很多主题可以查看themes.xml查看具体详细定义。

 



 

原创粉丝点击