android 状态栏浸透 状态栏半透明

来源:互联网 发布:电气预算软件 编辑:程序博客网 时间:2024/04/28 03:31

纯代码设置,不用修改manifest


首先这是主界面.xml:

<RelativeLayout 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"    style="@style/SystemWindows"    tools:context="com.example.administrator.aslibrary.MainActivity"></RelativeLayout>

两种情况:

第一种 去掉xml中 style  效果: 主界面置顶,可以实现半透明效果

Activity onCreat()中:

// 状态栏沉浸,4.4+生效 <<<<<<<<<<<<<<<<<if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//透明getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}SystemBarTintManager tintManager = new SystemBarTintManager(this);tintManager.setStatusBarTintEnabled(true);tintManager.setStatusBarTintResource(R.color.status_color_alpha);//状态背景色,#22000000// 状态栏沉浸,4.4+生效 >>>>>>>>>>>>>>>>>

第二种  加上style,效果: 主界面不置顶,动态设置状态栏颜色

<style name="SystemWindows">        <item name="android:clipToPadding">true</item>        <item name="android:fitsSystemWindows">true</item>    </style>

Activity 设置与第一种一样,颜色改为主题色不透明即可


1 0
原创粉丝点击