Reputation: 57
I want to make so my status bar is transparent, but also without icons on it. I managed to make it so that bar disappeared, but then it left a line that isn't filled with the background. I want to change that so i can actually see the background without any icons being in the way.
Also, I'm testing it on Xiaomi Redmi Note 8T
Code (with the result seen on the 1st picture)
MainActivity.kt
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
class MainActivity : AppCompatActivity() {
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) hideSystemUI()
}
private fun hideSystemUI() {SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
override fun onCreate(savedInstanceState: Bundle?) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Both themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.TestingSystemModes" parent="Theme.Design.NoActionBar">
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
</resources>
Here is how it looks with that line:
I want it to look like in the picture below, but without that status bar's icons:
EDIT: I think, it's phone that makes it like that ( in the center there is a camera ) and probably the black line is made to blend in the camera. That's why, whatever i did it didn't disappear. Still, thanks a lot to everyone who tried to help me.
Upvotes: 2
Views: 809
Reputation: 3292
The problem:
Phone's can now have a "cut-out" (for notched phones etc. etc.), and when you hide the status bar properly, the phone thinks "ok, I need to make the former status bar just a black cut-out so it doesn't look silly."
The solution:
There's actually four things you need to do:
The Code:
The below is a neat little extension function that will cover steps 1 and 3... (hide the status bars, set decorFitsSystemWindows
to false). This allows, in your activity to simply put window.setInImmersiveMode()
fun Window.setInImmersiveMode() {
val windowInsetsController = ViewCompat.getWindowInsetsController(decorView) ?: return
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars())
WindowCompat.setDecorFitsSystemWindows(this, false)
}
You need to change your themes.xml to tell Android to draw behind these cutouts, with this line (api 27 and above only, hence the tools:targetApi part):
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item>
And finally, there's a slightly more complex bit of code to handle setting up the bottom insets for your layout - again I've made it into an extension function so you can call view.setupInsets()
:
fun View.setupInsets() {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.layoutParams = (view.layoutParams as FrameLayout.LayoutParams).apply {
bottomMargin = insets.bottom
}
WindowInsetsCompat.CONSUMED
}
}
Upvotes: 2
Reputation: 23
you can use below lines to make it transparent or can set fix color getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); getWindow().setStatusBarColor(ContextCompat.getColor(ContactUsActivity.this,R.color.white));// set status background white
Upvotes: 0
Reputation: 951
Set these properties in your theme. Thats all
<item name="android:windowTranslucentStatus">true</item>
Upvotes: 0