Created
November 4, 2020 19:21
-
-
Save MotasemF/5f7b8be12f6480c427afd3105f827690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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