Possible overdraw: Root element paints background with a theme that also paints a background の警告を解消する
2021/01/12
ボトムナビゲーション単独のlayoutを作ってincludeしたい時に、Inspect Codeするとroot要素に背景を設定するなと警告が出ます。(フラグメント未使用のアプリ)
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.bottomnavigation.BottomNavigationView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:itemIconTint="@drawable/navigation"
app:menu="@menu/navigation" />
こうゆう時はmergeで囲ってしまうと解消できます。mergeはincludeで読み込まれた時に無くなる要素です。
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:itemIconTint="@drawable/navigation"
app:menu="@menu/navigation" />
</merge>
あるいは、テーマ側の背景を無効にしてもOKです。しかし、これをすると、背景が無くなって各要素に設定しないといけなくなるので正直キツイです。
<item name="android:windowBackground">@null</item>