Reputation: 5259
I used a toolbar in my Android application for years and never had a problem with it, but starting with Android 15 (API Level 35) my toolbar icons got overlayed with system Android icons on the top of the screen (see power button in the right upper corner overlapped with system's battery icon). Is there any way to fix it? The resource describing the toolbar is as follows:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/watch"
android:orderInCategory="2"
app:showAsAction="always"
android:visible="true"
android:title=""
android:icon="@drawable/gear"
/>
<item
android:id="@+id/show"
android:orderInCategory="3"
app:showAsAction="always"
android:visible="true"
android:icon="@drawable/eye"
android:title=""
/>
<item
android:id="@+id/copy"
android:orderInCategory="4"
app:showAsAction="always"
android:visible="true"
android:icon="@drawable/copy"
android:title=""
/>
<item
android:id="@+id/delete"
android:orderInCategory="5"
app:showAsAction="always"
android:visible="true"
android:icon="@drawable/delete"
android:title=""
/>
<item
android:id="@+id/exit"
android:orderInCategory="6"
app:showAsAction="always"
android:visible="true"
android:icon="@drawable/power"
android:title=""
/>
</menu>
The toolbar's layout is very much standard as well and is derived from the MaterialToolbar according to the Google's guidelines:
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/rootToolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorPrimaryDark"/>
Upvotes: 1
Views: 203
Reputation: 322
If you are using AppBarLayout
, you have to add android:fitsSystemWindows="true"
to it.
Add it to the AppBarLayout and not to the root layout. Adding it to the root will move the complete view down, which is usually not what you want.
For reference: https://developer.android.com/about/versions/15/behavior-changes-15?hl=de#not-edge-to-edge
Upvotes: 0
Reputation: 5259
The suggested answer solves the problem partially: it does offset the app's view, but it also erases the system icons.
I don't want them to be erased, because they might have a value for a user, and this is how it was in all Android versions up to API 34.
My solution looks more like a hack but it fixes the problem and makes the app look like in API 34 and all prior version
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM){
binding.rootToolbar.setPadding(0,
binding.rootToolbar.minimumHeight/2, 0, 0)
}
Yes, it's ugly but it works and now I have what I wanted: Thanks Google for breaking the code again.
@atzarul, if you know what else I can tweak in API 35 to return to the old look, please share
Upvotes: 0
Reputation: 56
You are probably missing android:fitsSystemWindows="true"
in the root layout that hosts your toolbar. Check the changes introduced by Android 15 (see 3rd bullet point).
Upvotes: 1