对状态栏(Status Bar)和下方导航栏(Navigation Bar)进行半透明处理

转载自Android 4.4+ 实现半透明状态栏(Translucent Bars) - CSDN博客 http://blog.csdn.net/leejizhou/article/details/48232015,亲自尝试了一下,感觉还不错

从原作者那里盗的图片(我的测试机没有下方导航栏,只有顶部状态栏,亲测顶部状态栏效果就如作者显示的一模一样):

下面说说如何使用这种效果:

1:在onCreate里面代码设置半透明的属性,由于只有Android 4.4以上才支持这种效果,所以代码需要判断下

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明底部导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
         }

2:在这个界面上我去掉了Actionbar,实现方式有很多,这里我使用的是在Style里去掉。

  <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

3:这个部分需要留意一下,如果希望APP的显示内容正常和滚动透明化需要加上android:fitsSystemWindows=”true”和android:clipToPadding=”false”的属性,建议你把这两个属性好好试试加上与否的区别。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:background="#795548"
    tools:context=".DefaultActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:textColor="#ffffff"
        android:text="@string/str" />

</ScrollView>

(这两个属性我设置前后,没有发现任何区别,不知道是不是我没观察得仔细。。。)
这样一个简单的半透明化效果就实现了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值