实现步骤:
一、下载第三方开源库https://github.com/jgilfelt/SystemBarTint(注意事项,V19以上才会出现透明)
二、项目目录res下新建values-v19文件夹,添加style.xml文件,内容以下java
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor"> <!-- Customize your theme here. --> </style> </resources>
三、Activity中设置状态栏透明android
<RelativeLayout xmlns:android=" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:clipToPadding="true">
就是添加git
android:fitsSystemWindows="true" android:clipToPadding="true"
若是还想改变状态栏的背景色,在oncreate里github
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); //tintManager.setNavigationBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.RED); //或者 tintManager.setTintColor(Color.parseColor("#ff0000")); }