androidandroid-mapviewandroid-maps-v2android-mapsandroid-fullscreen

Some controls of Google Map view are under status bar and toolbar


I have an app with transparent toolbar and statusbar and there is map which takes all space of the display but I need to move native controls of Google's map view under toolbar somehow

enter image description here

How can it be solved? For example right now I can't reset rotation (click on circle button)


Solution

  • We can use GoogleMap.setPadding()

    Implemented this solution (portrait mode only!):

    val view = binding.root
    val statusBarHeight = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        view.rootWindowInsets.getInsets(WindowInsets.Type.systemBars()).top
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        @Suppress("DEPRECATION")
        view.rootWindowInsets.stableInsetTop
    } else {
        // 24dp
        resources.getDimension(R.dimen.status_bar_height).toInt()
    }
    var topMargin = statusBarHeight
    val tv = TypedValue()
    if (requireActivity().theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        val actionBarHeight =
            TypedValue.complexToDimensionPixelSize(tv.data, resources.displayMetrics)
        topMargin += actionBarHeight
    }
    
    googleMap.setPadding(0, topMargin, 0, 0)