Pour tester kotlin avec anko DSL j'ai décidé de démarrer un nouveau projet dans le dernier android studio ide (2.1.3), en utilisant le plugin kotlin (1.0.3) et la dernière bibliothèque anko (0.9)Statusbar n'est pas transparent mais blanc
J'ai utilisé l'activité de tiroir Navigation par défaut du projet, donc j'ai juste dû convertir le fichier XML principal en anko.
C'est le 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>
Et il fonctionne parfaitement, comme vous pouvez le voir ici:
Avec anko, j'ai essayé de copier tous les détails du xml, obtenir ce code :
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
}
}
}
}
Et au lieu, je reçois cette barre d'état blanc:
Les seules modifications que j'ai faites ont été dans le MainActivity changer le setContentView (R.layout.activity_main), à MainActivityUi.setContentView (this). Donc, ma question est la suivante: pourquoi cela se produit-il alors que ce sont les mêmes vues et les mêmes mises en page? et comment puis-je résoudre ce problème?
EDIT: J'utilise le programme par défaut qu'il est créé lorsque vous choisissez un nouveau projet dans Android Studio, puis vous choisissez DrawerNavigationActivity. Si dans setContentView je choisis d'afficher la vue du xml, la barre d'état est bleue (première capture d'écran), mais si je choisis d'afficher la vue de l'anko, j'obtiens la barre d'état blanche.
Dans les deux cas, je suis en utilisant des thèmes mêmes, etc, les couleurs, et lors de l'utilisation de la mise en page XML, tout fonctionne parfaitement, il doit y avoir un problème de anko
Avez-vous essayé de mettre fitsSystemWindows = true à appBarLayout? – Stepango
Exactement le même problème ici, je mets juste un «tiroir», la barre d'état avait un fond blanc là-bas. idk, mais avec xml cela fonctionne très bien. – MewX