Activity 透明 半透明效果的简单实现

来源:互联网 发布:淘宝号为什么会被限购 编辑:程序博客网 时间:2024/06/11 02:20

一.全透明效果

Activity实现全透明效果很容易实现,android自带的主题样式已经帮我们做好了,直接引用就可以了,在AndroidManifest.xml中的需要透明效果的activity节点下添加下面代码:

android:theme="@android:style/Theme.Translucent"
或者
android:theme="@android:style/Theme.Translucent.NoTitleBar"

二.半透明效果

参考android自带样式的全透明效果(添加到styles样式中):

  <style name="halfTranslucent">        <item name="android:windowBackground">@android:color/transparent</item>        <item name="android:colorBackgroundCacheHint">@null</item>        <item name="android:windowIsTranslucent">true</item>        <!-- Note that we use the base animation style here (that is no             animations) because we really have no idea how this kind of             activity will be used. -->        <item name="android:windowAnimationStyle">@android:style/Animation</item>    </style>
</pre>android:windowBackground:表示背景样式(这里改成自己想要的透明程度就可以了),eg:<p></p><p></p><pre code_snippet_id="355983" snippet_file_name="blog_20140521_5_5862737" name="code" class="html"><color name="ljg_transparent_background">#90000000</color>

android:colorBackgroundCacheHint:空表示不要使用缓存

android:windowIsTranslucent":是否透明,默认给true

android:windowAnimationStyle 打开的动画样式,默认的的动画是没有的;eg:

<!-- Base style for animations.  This style specifies no animations. -->    <style name="Animation" />
这里可以改成我们想要的动画效果具体可以参考:

\sdk\platforms\android-16\data\res\anim\里的内容

不需要标题栏的话,添加下面的代码

<item name="android:windowNoTitle">true</item><item name="android:windowContentOverlay">@null</item>


最后在AndroidManifest.xml中的需要透明效果的activity节点下添加该我们自定义的主题样式就可以了.




0 0
原创粉丝点击