Kotlin / anko

Pleasant Android application development
Apache License 2.0
15.89k stars 1.29k forks source link

NavigationDrawer makes status bar with white background #298

Open MewX opened 7 years ago

MewX commented 7 years ago

Same problem with: http://stackoverflow.com/questions/39296436/statusbar-is-not-transparent-but-white

With the automatical generated XML, the status bar background shows normally and correctly, even when I simplified it to this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

But when I use Anko like this, the status bar shows white & non-transparent background all the time:

override fun createView(ui: AnkoContext<MainActivity>) = with(ui) {
    drawerLayout {  }
}

Or, I tried this code as well:

ankoView(::NavigationView, R.style.theme.AppTheme_NoActionBar) {  }

Still white background like this (for the effects, I added other views): screenshot_1484822965

Miha-x64 commented 7 years ago

In DrawerLayout(Context, AttributeSet), it does some work related to fitsSystemWindows XML property. So, as a workaround, I have the only XML layout in my project — an empty Drawer. :)

Miha-x64 commented 7 years ago

IMO, a related problem: if you create a typical layout:

drawerLayout {
    coordinatorLayout {
        themedAppBarLayout(R.style.AppTheme_AppBarOverlay) {
            toolbar {
                popupTheme = R.style.AppTheme_PopupOverlay
                backgroundResource = R.color.colorPrimary
            }.lparams(width = matchParent) {
                height = TypedValue.complexToDimension(context.attr(R.attr.actionBarSize).data, resources.displayMetrics).toInt()
            }
        }
    }
}

, you will be able to move a toolbar under the statusbar by your finger, which is wrong and impossible when a layout inflated from XML.

All view class constructors should be examined, and a list of precautions created. Also, it's possible to emulate XML inflation by creating AttributeSets from code, but this is kinda quirky and crutchy.

Corsage commented 6 years ago

In regards to the movable toolbar, there is a workaround posted here: https://stackoverflow.com/questions/42189235/why-does-this-anko-layout-not-handle-the-system-ui-correctly

Which states, adding behavior = AppBarLayout.ScrollingViewBehavior() to the themedAppBarLayout should fix the movable toolbar.

Just wanted to add this to get more transparency.