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

一.全透明效果

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值