anot DSL로 kotlin을 테스트하려면 kotlin 플러그인 (1.0.3)과 최신 anko 라이브러리 (0.9.3)를 사용하여 마지막 android studio ide (2.1.3)에서 새로운 proyect를 시작하기로 결정했습니다.상태 표시 줄이 투명하지 않고 흰색이 아닙니다
기본 proyect Navigation Drawer Activity를 사용 했으므로 main xml을 anko로 변환해야했습니다.
이
은 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>
그리고 당신은 여기에서 볼 수 있듯이 그것이 완벽하게 작동된다 ANKO와
을,이 코드를 얻기는 XML에서 모든 세부 사항을 복사하려고 :
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
}
}
}
}
을
MainActivity에서 변경된 사항은 setContentView (R.layout.activity_main)를 MainActivityUi.setContentView (this)로 변경 한 것뿐입니다.
그래서 내 질문은 왜 그들이 같은보기와 레이아웃 일 때입니까? 어떻게 해결할 수 있습니까?
EDIT : Android Studio에서 새 proyect를 선택한 다음 DrawerNavigationActivity를 선택할 때 생성되는 기본 proyect를 사용하고 있습니다. setContentView에서 xml 뷰를 표시하도록 선택하면 상태 표시 줄이 파란색 (첫 번째 스크린 샷)이지만 anko의 뷰를 표시하도록 선택하면 흰색 상태 표시 줄이 나타납니다. 두 경우 모두
, 나는 등 같은 주제, 색상을 사용하고, 그리고 XML 레이아웃을 사용하는 경우, 모든 것이 완벽하게 작동한다, 그래서 당신은 상태가 잘못 생각하고
fitsSystemWindows = true를 appBarLayout으로 설정하려고 했습니까? – Stepango
정확히 같은 문제가 여기에 있는데, 나는 '서랍'을 넣었습니다. 상태 표시 줄에는 흰색 배경이있었습니다. idk,하지만 xml은 아주 잘 작동합니다. – MewX