Reputation: 103
can i change the status bar icon color? only icon.. no background. I try with setStatusBarColor with white color. Then icon like o'clock, wifi, battery not visible because it uses white. Result :
For example i want to change icon in status bar to black and background status bar is white, result like this..
could this happen in android studio?
Upvotes: 0
Views: 1040
Reputation: 686
Yes, it is possible. Add this style to your theme.xml.
<style name="WhiteStatusBar" parent="Your app theme">
<item name="android:statusBarColor" tools:targetApi="l">@color/white</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
</style>
Go to your app AndroidManifest.xml and add above theme to your activity.
<activity
android:name=".activity"
android:theme="@style/WhiteStatusBar"
android:exported="false" />
Upvotes: 1
Reputation: 232
Yes, You can change text and icon color using the below code
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Here is My fully working code, including changing background color with icon and text color.
open fun getStatusBarHeight(context: Context): Int {
var result = 0
val resourceId = context.resources.getIdentifier("status_bar_height", "dimen", "android")
if (resourceId > 0) {
result = context.resources.getDimensionPixelSize(resourceId)
}
return result
}
open fun setWindowFullScreen(tbMain: Toolbar) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!isDarkTheme()) {
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
window.decorView.systemUiVisibility =
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
tbMain.setPadding(0, getStatusBarHeight(this), 0, 0)
}
open fun setWindowFlag(activity: Activity, bits: Int, on: Boolean) {
val window = activity.window
val winParams = window.attributes
if (on) {
winParams.flags = winParams.flags or bits
} else {
winParams.flags = winParams.flags and bits.inv()
}
window.attributes = winParams
}
you just need to call setWindowFullScreen(tbMain) method from your activity with the toolbar parameter.
Upvotes: 1