---
title: "主题属性"
author: "test_angel"
date: "2012-09-06T16:16:23Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2012-09-06T16:16:23Z"
id: 1638823
url: "https://test-angel.iteye.com/blog/1638823"
---

常常需要对activity的主题进行设置，下面我就将一些常用的属性总结一下，方便自己以后使用！～～～

 

1.以下是一个常用的style：

 

```
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="CustomTheme">
 <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>
```

 

 

注意：

      用了@符号和？符号来应用资源。

     @符号表明了我们应用的资源是前边定义过的(或者在前一个项目中或者在Android 框架中)。

     ？表明了我们引用的资源的值在当前的主题当中定义过。通过引用在&lt;item&gt;里边定义的名字可以做到(*panelTextColor* 用的颜色和*panelForegroundColor中定义的一样* )。这中技巧只能用在XML资源当中。

例如：

&lt;!-- Window attributes --&gt;

        &lt;item name="windowBackground"&gt;@android:drawable/screen\_background\_dark&lt;/item&gt;  
        &lt;item name="windowFrame"&gt;@null&lt;/item&gt;  
        &lt;item name="windowNoTitle"&gt;false&lt;/item&gt;  
        &lt;item name="windowFullscreen"&gt;false&lt;/item&gt;  
        &lt;item name="windowIsFloating"&gt;false&lt;/item&gt;  
        &lt;item name="windowContentOverlay"&gt;@android:drawable/title\_bar\_shadow&lt;/item&gt;  
        &lt;item name="windowTitleStyle"&gt;@android:style/WindowTitle&lt;/item&gt;  
        &lt;item name="windowTitleSize"&gt;25dip&lt;/item&gt;  
        &lt;item name="windowTitleBackgroundStyle"&gt;@android:style/WindowTitleBackground&lt;/item&gt;  
        &lt;item name="android:windowAnimationStyle"&gt;@android:style/Animation.Activity&lt;/item&gt;

 

2.在主题中我们还可以设置页面的动画，属性如下：

Animation定义：  
&lt;!-- Standard animations for a full-screen window or activity. --&gt;  
    &lt;style name="Animation.Activity"&gt;  
        &lt;item name="activityOpenEnterAnimation"&gt;@anim/activity\_open\_enter&lt;/item&gt;  
        &lt;item name="activityOpenExitAnimation"&gt;@anim/activity\_open\_exit&lt;/item&gt;  
        &lt;item name="activityCloseEnterAnimation"&gt;@anim/activity\_close\_enter&lt;/item&gt;  
        &lt;item name="activityCloseExitAnimation"&gt;@anim/activity\_close\_exit&lt;/item&gt;

        &lt;item name="taskOpenEnterAnimation"&gt;@anim/activity\_open\_enter&lt;/item&gt;  
        &lt;item name="taskOpenExitAnimation"&gt;@anim/activity\_open\_exit&lt;/item&gt;  
        &lt;item name="taskCloseEnterAnimation"&gt;@anim/activity\_close\_enter&lt;/item&gt;  
        &lt;item name="taskCloseExitAnimation"&gt;@anim/activity\_close\_exit&lt;/item&gt;  
    
        &lt;item name="taskToFrontEnterAnimation"&gt;@anim/activity\_open\_enter&lt;/item&gt;  
        &lt;item name="taskToFrontExitAnimation"&gt;@anim/activity\_open\_exit&lt;/item&gt;  
        &lt;item name="taskToBackEnterAnimation"&gt;@anim/activity\_close\_enter&lt;/item&gt;  
        &lt;item name="taskToBackExitAnimation"&gt;@anim/activity\_close\_exit&lt;/item&gt;  
          
        &lt;item name="wallpaperOpenEnterAnimation"&gt;@anim/wallpaper\_open\_enter&lt;/item&gt;  
        &lt;item name="wallpaperOpenExitAnimation"&gt;@anim/wallpaper\_open\_exit&lt;/item&gt;  
        &lt;item name="wallpaperCloseEnterAnimation"&gt;@anim/wallpaper\_close\_enter&lt;/item&gt;  
        &lt;item name="wallpaperCloseExitAnimation"&gt;@anim/wallpaper\_close\_exit&lt;/item&gt;

        &lt;item name="wallpaperIntraOpenEnterAnimation"&gt;@anim/wallpaper\_intra\_open\_enter&lt;/item&gt;  
        &lt;item name="wallpaperIntraOpenExitAnimation"&gt;@anim/wallpaper\_intra\_open\_exit&lt;/item&gt;  
        &lt;item name="wallpaperIntraCloseEnterAnimation"&gt;@anim/wallpaper\_intra\_close\_enter&lt;/item&gt;  
        &lt;item name="wallpaperIntraCloseExitAnimation"&gt;@anim/wallpaper\_intra\_close\_exit&lt;/item&gt;

        &lt;item name="fragmentOpenEnterAnimation"&gt;@animator/fragment\_open\_enter&lt;/item&gt;  
        &lt;item name="fragmentOpenExitAnimation"&gt;@animator/fragment\_open\_exit&lt;/item&gt;  
        &lt;item name="fragmentCloseEnterAnimation"&gt;@animator/fragment\_close\_enter&lt;/item&gt;  
        &lt;item name="fragmentCloseExitAnimation"&gt;@animator/fragment\_close\_exit&lt;/item&gt;  
        &lt;item name="fragmentFadeEnterAnimation"&gt;@animator/fragment\_fade\_enter&lt;/item&gt;  
        &lt;item name="fragmentFadeExitAnimation"&gt;@animator/fragment\_fade\_exit&lt;/item&gt;  
    &lt;/style&gt;

 

3.一些系统的主题：

• 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 = "Translucent"   半透明    
•android:theme = "Theme.Translucent.NoTitleBar"  半透明、无标题栏    
•android:theme = "Theme.Translucent.NoTitleBar.Fullscreen"  半透明、无标题栏、全屏    
•android:theme = "Theme.Panel"     
•android:theme = "Theme.Light.Panel"