Skip to content

Commit

Permalink
Added a function for changing status bar color.
Browse files Browse the repository at this point in the history
pokk committed Jan 22, 2018
1 parent e7405ab commit f6733b6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion kotlinknifer/src/main/java/com/devrapid/kotlinknifer/View.kt
Original file line number Diff line number Diff line change
@@ -5,12 +5,15 @@ package com.devrapid.kotlinknifer
import android.app.Activity
import android.content.Context
import android.graphics.Rect
import android.os.Build
import android.support.annotation.ColorRes
import android.support.v7.app.AlertDialog
import android.view.View
import android.view.View.GONE
import android.view.View.INVISIBLE
import android.view.View.VISIBLE
import android.view.ViewTreeObserver
import android.view.WindowManager
import com.example.kotlinknifer.R

/**
@@ -88,4 +91,16 @@ inline fun Context.statusBarHeight() =

inline fun Activity.statusBarHeight() = Rect()
.apply { window.decorView.getWindowVisibleDisplayFrame(this) }
.top
.top

inline fun Activity.changeStatusBarColor(@ColorRes colorRes: Int) {
if (Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT)
window.apply {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
statusBarColor = getResColor(colorRes)
}
else {
TODO("Don't support the sdk version is less than 21 yet.")
}
}

0 comments on commit f6733b6

Please sign in to comment.