Skip to content

Instantly share code, notes, and snippets.

@MotasemF
Created November 4, 2020 19:21
Show Gist options
  • Save MotasemF/5f7b8be12f6480c427afd3105f827690 to your computer and use it in GitHub Desktop.
Save MotasemF/5f7b8be12f6480c427afd3105f827690 to your computer and use it in GitHub Desktop.
fun AppCompatActivity.setStatusBarTransparent() {
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
setWindowFlag(this, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false)
window.statusBarColor = Color.TRANSPARENT
}
private fun setWindowFlag(activity: Activity, bits: Int, on: Boolean) {
val win = activity.window
val winParams = win.attributes
if (on) {
winParams.flags = winParams.flags or bits
} else {
winParams.flags = winParams.flags and bits.inv()
}
win.attributes = winParams
}
// If you want for Splash screen to be transparent, you can create a new style and apply to your applicaion in Manifest(I did it as a full screen improvisation):
<application
android:name="package_name">
android:theme="@style/LaunchScreenTheme"
....</application>
<style name="LaunchScreenTheme" parent="AppTheme">
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@drawable/preview_screen</item>
<item name="windowActionBar">false</item>
</style>
// And in MainActivity, apply your App theme :)
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState)
setStatusBarTransparent()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment