實現步驟:
一、下載第三方開源庫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")); }