Reputation: 563
I use Kotlin to create an android app, I would like to know how to make the status bar completely transparent with dark text color with Kotlin I seen the following soltuion but not work for me Dark-text transparent status bar with opaque navigation bar Here's my following code :
if (VERSION.SDK_INT in 19..20) {
setWindowFlag(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, true)
}
if (VERSION.SDK_INT >= 19) {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
if (VERSION.SDK_INT >= 21) {
setWindowFlag(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, false)
window.statusBarColor = Color.TRANSPARENT
}
Here's the custom style in style.xml:
<style name="MyStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:navigationBarColor">@android:color/black</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
And my xml code :
<..... android:fitsSystemWindows="true" ....>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="189dp"
app:elevation="0dp"
android:theme="@style/MyStyle" ....>
I want to know where's the problem in my code and How can I correct it to get the status bar completely transparent with dark text color
Upvotes: 1
Views: 1755
Reputation: 704
You have to follow three steps.
Update your style.xml and main theme
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
In your main xml add
android:fitsSystemWindows="true"
In your activity before setcontView
add
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
Upvotes: 5