Um kotlin mit anko DSL zu testen, entschied ich mich, ein neues Projekt in der letzten android Studio IDE (2.1.3) zu starten, mit Kotlin Plugin (1.0.3) und neueste Anko-Bibliothek (0.9)Statusbar ist nicht transparent, aber weiß
Ich habe das Standardprojekt "Navigation Drawer Activity" verwendet, also musste ich einfach das Haupt-XML in anko konvertieren.
Dies ist der xml:
<?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"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<TextView
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Und es funktioniert perfekt, wie Sie hier sehen können:
Mit anko habe ich versucht, jedes Detail aus der XML zu kopieren, diesen Code bekommen :
class MainActivityUi: AnkoComponent<MainActivity> {
override fun createView(ui: AnkoContext<MainActivity>) = with(ui) {
drawerLayout {
id = R.id.drawer_layout
fitsSystemWindows = true
coordinatorLayout {
appBarLayout(R.style.AppTheme_AppBarOverlay) {
toolbar {
id = R.id.toolbar
backgroundColor = colorAttr(R.attr.colorPrimary)
popupTheme = R.style.AppTheme_PopupOverlay
}.lparams(height=dimenAttr(R.attr.actionBarSize),width=matchParent)
}.lparams(width=matchParent)
relativeLayout {
padding = dip(16)
textView("Hello World!")
}.lparams(height=matchParent,width=matchParent) {
behavior = AppBarLayout.ScrollingViewBehavior()
}
}.lparams(height=matchParent,width=matchParent)
navigationView {
id = R.id.nav_view
inflateHeaderView(R.layout.nav_header_main)
inflateMenu(R.menu.activity_main_drawer)
}.lparams(height=matchParent) {
gravity = Gravity.START
fitsSystemWindows = true
}
}
}
}
Und statt, ich bin diesen weißen statusbar bekommen:
Die einzigen Änderungen, die ich tat, war in der MainActivity ändern Sie die SetContentView (R.layout.activity_main), um MainActivityUi.setContentView (this).
Also, meine Frage ist, warum passiert das, wenn sie die gleichen Ansichten und Layouts sind? und wie kann ich das beheben?
BEARBEITEN: Ich benutze das Standardprojekt, das es erstellt wird, wenn Sie in Android Studio neues Projekt auswählen, und dann wählen Sie DrawerNavigationActivity. Wenn ich in setContentView die XML-Ansicht anzeigen lasse, ist die Statusleiste blau (erster Screenshot), aber wenn ich die Anko-Ansicht anzeigen lasse, erhalte ich die weiße Statusleiste.
In beiden Fällen ist ich mit gleichen Themen, Farben, etc, und wenn das XML-Layout verwenden, perfekt funktioniert alles, also muss es einen anko des Problem
haben Sie versucht, FitSystemWindows = True zu appBarLayout zu setzen? – Stepango
Genau das gleiche Problem hier, ich habe nur ein 'Schublade', die Statusleiste hatte einen weißen Hintergrund da draußen. idk, aber mit xml funktioniert es ganz gut. – MewX