application content goes behind the navigation bar in android L
Here is the solution.
Most of the layouts get solved by adding these properties in values-v21 style.xml
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:fitsSystemWindows">true</item>
for others, I have calculated the hight of navigation bar and add margin to my view .
public static int getSoftButtonsBarSizePort(Activity activity) {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}
Note: By using the above solutions everything work but I was also using PopupWindow in my app.The layout of the PopupWindow get messed up in android L. Look for the issue and the solution here
NavigationBar and StatusBar not fully transparent on some devices
I found the solution to this problem. As Eugen Pechance pointed out, the first two lines of my original styles.xml
are unnecessary. However, the main thing causing the half-transparent background were android:enforceStatusBarContrast
and android:enforceNavigationBarContrast
lines. The way that android enforces the contras is by adding that semi-transparent background to the status and navigation bar, which is not the way I thought it works. Setting these values to false
does the trick.
Also, according to this article you should add the following line to the MainActivity.java
get the content to go behind the status and navigation views:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
super.onCreate(savedInstanceState);
}
Make sure that you override the correct onCreate
function, since the default overriden function in react native doesn't get called.
Transparent status bar (with visible navigation bar)
Step 1: To make the status bar transparent: add the below into the style themes.xml
or sytles.xml
:
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
Step 2: Then in activity to make the status bar overlaps with the activity:
The used window flags are deprecated as of API level 30, so they can be used till API level 29:
if (Build.VERSION.SDK_INT in 21..29) {
window.statusBarColor = Color.TRANSPARENT
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.decorView.systemUiVisibility =
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or SYSTEM_UI_FLAG_LAYOUT_STABLE
} else if (Build.VERSION.SDK_INT >= 30) {
window.statusBarColor = Color.TRANSPARENT
// Making status bar overlaps with the activity
WindowCompat.setDecorFitsSystemWindows(window, false)
}
UPDATE For API-30
This doesn't actually make the status bar transparent, it makes it translucent and will still have a shadow to it
This is right on API-30, and reason because setting <item name="android:windowTranslucentStatus">true</item>
.
Actually the <item name="android:windowTranslucentStatus">true</item>
is only required on API level 19. If your app is greater than that, you can dismiss it at all.
Anyways, the way to fix this is to override the themes.xml/styles.xml in API-30; i.e. to have a res\values-v30\themes.xml
; you can just add the main app theme like:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.TransparentStatusBar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
</style>
</resources>
UPDATE 2 For API-30
Just discovered a bug on API 30 that the bottom navigation overlaps with the activity obscuring the bottom part of it, that probably couldn't be discovered by the OP as they are using a map.
To solve this, As per documentation:
You can address overlaps by reacting to insets, which specify which
parts of the screen intersect with system UI such as the navigation
bar or the status bar. Intersecting can mean simply being displayed
above the content, but it can also inform your app about system
gestures, too.
So, we need to handle the System bars insets for API level 30+ to avoid your app overlapping with the navigation bar:
This requires the top root ViewGroup
of the activity layout, and accordingly the LayoutParams
need to be coasted appropriately.
Here I am using a ConstraintLayout
as a root layout, and FrameLayout.LayoutParams
:
/*
* Making the Navigation system bar not overlapping with the activity
*/
if (Build.VERSION.SDK_INT >= 30) {
// Root ViewGroup of my activity
val root = findViewById<ConstraintLayout>(R.id.root)
ViewCompat.setOnApplyWindowInsetsListener(root) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
// Apply the insets as a margin to the view. Here the system is setting
// only the bottom, left, and right dimensions, but apply whichever insets are
// appropriate to your layout. You can also update the view padding
// if that's more appropriate.
view.layoutParams = (view.layoutParams as FrameLayout.LayoutParams).apply {
leftMargin = insets.left
bottomMargin = insets.bottom
rightMargin = insets.right
}
// Return CONSUMED if you don't want want the window insets to keep being
// passed down to descendant views.
WindowInsetsCompat.CONSUMED
}
}
This is tested on 8 devices/emulators on the range of API level 19 to API level 30.
How to place Left Navigation Bar behind Status Bar? - SystemUI - Android - AOSP
I think it was intended. StatusBar has lower layer type than navigation type. Which means navigation view is in front of StatusBar.
/**
* Window type: the status bar. There can be only one status bar
* window; it is placed at the top of the screen, and all other
* windows are shifted down so they are below it.
* In multiuser systems shows on all users' windows.
*/
public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW;
.....
/**
* Window type: Navigation bar (when distinct from status bar)
* In multiuser systems shows on all users' windows.
* @hide
*/
public static final int TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;
As a walk around, You can modify the layout param of navigation bar. You can set y to getStatusBarHeight()
and gravity to Gravity.BOTTOM
- Never tested.
Related Topics
Android Gcm (Push Notification): Device Doesn't Receive Notification If Application Is Stopped
Multiple Apps Use Same Content Provider
Android Get a Cursor Only with Contacts That Have an Email Listed >Android 2.0
Pass Parameter with Volley Post
Javamail API in Android Using Xoauth
How to Send JSON Object to the Server from My Android App
How to Dynamically Change an App Icon Like Calendar App Does
Android Broadcastreceiver for Volume Key Up and Down
How to Sign My Application with the System Signature Key
Getallcellinfo Returns Null in Android 4.2.1
Update Support Library 23.2.0 Build Bug
Event for Videoview Playback State or Mediacontroller Play/Pause
Findviewbyid Returns Null When Using Fragment
Set Build Path in Eclipse for Ndk Program
Getting Context in Androidtestcase or Instrumentationtestcase in Android Studio's Unit Test Feature