常常需要对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 框架中)。
?表明了我们引用的资源的值在当前的主题当中定义过。通过引用在<item>里边定义的名字可以做到(panelTextColor 用的颜色和panelForegroundColor中定义的一样)。这中技巧只能用在XML资源当中。
例如:
<!-- Window attributes -->
<item name="windowBackground">@android:drawable/screen_background_dark</item>
<itemname="windowFrame">@null</item>
<itemname="windowNoTitle">false</item>
<itemname="windowFullscreen">false</item>
<itemname="windowIsFloating">false</item>
<itemname="windowContentOverlay">@android:drawable/title_bar_shadow</item>
<itemname="windowTitleStyle">@android:style/WindowTitle</item>
<itemname="windowTitleSize">25dip</item>
<itemname="windowTitleBackgroundStyle">@android:style/WindowTitleBackground</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Activity</item>2.在主题中我们还可以设置页面的动画,属性如下:
Animation定义:
<!--Standardanimationsforafull-screenwindoworactivity.-->
<stylename="Animation.Activity">
<itemname="activityOpenEnterAnimation">@anim/activity_open_enter</item>
<itemname="activityOpenExitAnimation">@anim/activity_open_exit</item>
<itemname="activityCloseEnterAnimation">@anim/activity_close_enter</item>
<itemname="activityCloseExitAnimation">@anim/activity_close_exit</item>
<itemname="taskOpenEnterAnimation">@anim/activity_open_enter</item>
<itemname="taskOpenExitAnimation">@anim/activity_open_exit</item>
<itemname="taskCloseEnterAnimation">@anim/activity_close_enter</item>
<itemname="taskCloseExitAnimation">@anim/activity_close_exit</item>
<itemname="taskToFrontEnterAnimation">@anim/activity_open_enter</item>
<itemname="taskToFrontExitAnimation">@anim/activity_open_exit</item>
<itemname="taskToBackEnterAnimation">@anim/activity_close_enter</item>
<itemname="taskToBackExitAnimation">@anim/activity_close_exit</item>
<itemname="wallpaperOpenEnterAnimation">@anim/wallpaper_open_enter</item>
<itemname="wallpaperOpenExitAnimation">@anim/wallpaper_open_exit</item>
<itemname="wallpaperCloseEnterAnimation">@anim/wallpaper_close_enter</item>
<item name="wallpaperCloseExitAnimation">@anim/wallpaper_close_exit</item><itemname="wallpaperIntraOpenEnterAnimation">@anim/wallpaper_intra_open_enter</item>
<itemname="wallpaperIntraOpenExitAnimation">@anim/wallpaper_intra_open_exit</item>
<itemname="wallpaperIntraCloseEnterAnimation">@anim/wallpaper_intra_close_enter</item>
<item name="wallpaperIntraCloseExitAnimation">@anim/wallpaper_intra_close_exit</item><itemname="fragmentOpenEnterAnimation">@animator/fragment_open_enter</item>
<itemname="fragmentOpenExitAnimation">@animator/fragment_open_exit</item>
<itemname="fragmentCloseEnterAnimation">@animator/fragment_close_enter</item>
<itemname="fragmentCloseExitAnimation">@animator/fragment_close_exit</item>
<itemname="fragmentFadeEnterAnimation">@animator/fragment_fade_enter</item>
<itemname="fragmentFadeExitAnimation">@animator/fragment_fade_exit</item>
</style>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"