In your theme
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
<item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
In your layout
android:fitsSystemWindows="true"
In your activity
if (Build.VERSION.SDK_INT >= 21) {
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
navbar.setPadding(0, getStatusBarHeight(), 0, 0)
}
fun getStatusBarHeight(): Int {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId)
} else {
return 0
}
}
In your theme
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
In your layout
android:fitsSystemWindows="true"
In your activity
if (Build.VERSION.SDK_INT >= 21) {
toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
navbar.setPadding(0, getStatusBarHeight(), 0, 0)
}
fun getStatusBarHeight(): Int {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId)
} else {
return 0
}
}
In your theme
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/holo_red_dark</item>
<item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/holo_red_dark</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item>