Can I set FLAG_LAYOUT_NO_LIMITS only for status bar?
Solution 1
this work for me
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
styles.xml
<style name="TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
v21\styles.xml
<style name="TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
status bar will be transparent or translucent, navigation bar won't
hope this helps!
Solution 2
using mikepenz's comment
what I exactly working code (converted to kotlin) below here.
// at AppCompatActivity, min SDK is 16, I tested api 25
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
if (Build.VERSION.SDK_INT >= 19) {
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
if (Build.VERSION.SDK_INT >= 21) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.statusBarColor = Color.TRANSPARENT
}
setContentView(R.layout.activity_main)
}
Solution 3
Scroll down to check how the end result looks like
First of all, define your styles.xml something like this-
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
DO NOT add the following line
<item name="android:windowTranslucentStatus">true</item>
Adding above line will NOT shift the layout up when the soft keyboard is shown on a Dialog with an EditText
Then override this style in v21 and v23 styles like this-
v21/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>
v23/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>
Activity code - Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(
LayoutParams.FLAG_LAYOUT_NO_LIMITS,
LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
setContentView(R.layout.YOUR_LAYOUT_RESOURCE_ID)
.
.
.
}
Activity code - Java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(
LayoutParams.FLAG_LAYOUT_NO_LIMITS,
LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
setContentView(R.layout.YOUR_LAYOUT_RESOURCE_ID)
.
.
.
}
Solution 4
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
Solution 5
fun showTransparentStatusbar() {
activity!!.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
fun removeStatusbarFlags() {
activity!!.window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
BArtWell
Updated on August 27, 2020Comments
-
BArtWell almost 4 years
I need to make transparent status bar. I am using
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
and it is make status bar as I want. But it also affect navigation bar: it became transparent andgetWindow().setNavigationBarColor(Color.BLACK)
do nothing.Is there way to make transparent status bar only and not navigation bar?
-
samurdhilbk over 6 yearsThis solution does the job as described. The navigation bar is opaque and there is no content under it.
-
Robokishan over 5 yearswhich Android are you using because its for older android 6 or 7
-
Shashank Degloorkar over 5 yearsPerfect and concise answer. Kudos
-
BST Kaal over 5 yearsFinally ! A precise and original answer.
-
Aanal Shah about 5 yearsIt worked for me. Additionally all I have to do is just adjust my layout top according to status bar. Thank you so much :)
-
Rajkiran almost 5 years@NikunjPatel It worked for me (and 4 others). Can you post your code as a question where it is not working for you and send the link here. Maybe I can help.
-
smoothumut almost 5 yearsthanks only this one worked for me. clean and precise. no need for extra info
-
Abdul Mateen over 4 yearsIt doesn't make the status bar transparent. It simply hides the status bar.
-
phamxuanlu over 4 yearsAlmost device is work well but It isn't work on Samsung Note 10+ running Android 10 and One UI 2.0 The navigation bar still transparent and overlap app's content.
-
Karsh Soni almost 4 yearsprevent scroll view from scrolling
-
Alexey Timokhin almost 4 yearsThat doesn't work on Samsung SM-T295 (Android 10, One UI 2.1). The navigation bar appears on top of the content.
-
Alexey Timokhin almost 4 yearsit makes the status bar disappear
-
AndreasReiff over 3 yearsThis does not work! I can't set light theme on the navigation bar. Only white buttons with black translucent background.
-
Shunan about 3 yearsYou are right.. i tried it and didn't regret it
-
hmac over 2 yearswindow.decorView.systemUiVisibility = window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN Is better (I needed this to keep status bar icons black instead of white)
-
famfamfam over 2 yearsFLAG_LAYOUT_NO_LIMITS hide actionbar
-
famfamfam over 2 yearsdid u solved this?
-
famfamfam over 2 yearsthis hide my toolbar?
-
famfamfam over 2 yearsthis hide my toolbar?
-
famfamfam over 2 yearsyou just adjust margin of your view, so what did i do if i have toolbar?
-
Eugene P. over 2 yearsThat was 3 years ago ) Yep. WindowManager.LayoutParams.FLAG_FULLSCREEN worked for nexus 5.
-
TheJudge over 2 yearswhat do you mean ? I set margin to root component of my layout. In that layout I also have Toolbar