android中能够经过对activity主题进行设置,能够获得一些特殊的效果,如背景透明、无标题、全屏等,android自己提供了一些主题供开发者选择,具体方法即在manifest文件中相应的<activity>标签下添加android:theme="@android :style/..."便可。,若是要自定义主题,须要在res/values目录下添加style.xml文件,在其中定义所需的属性。java
遇到的问题:android
应用中须要将一个activity的背景设置为半透明效果,但系统自己提供的选择只有全透明效果,所以须要自定义。web
定义activity背景色 <item name="windowBackground">#99cccccc</item>,这样写会报出两种错误,api
(1) No resource found that matches the given name: attr 'windowBackground',即指定的name找不到,这条有时候会经过,但背景不会改变,是漆黑的一片。spa
(2) Color types not allowed (at 'android:windowBackground' with value '#99cccccc'),即对color不能这么写.net
解决办法:code
<item name="android:windowBackground">@color/transparent_background</item>orm
即name里要添加android:,color要专门在colors.xml文件中具体定义xml
分析:ip
<item name="windowBackground">这种写法是在仿照系统api中的style写的,在目录\android-sdk\platforms\android-8\data\res\values下的themes.xml文件是系统定义的各类主题属性,例如
<!-- Window attributes --> <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="windowShowWallpaper">false</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> <item name="android:windowSoftInputMode">stateUnspecified|adjustUnspecified</item>
不知道为何系统文件就没有问题。。。总之自定义的话对这些属性值的name需添加android:,形如<item name="android:windowBackground">