anthaugh
04/24/2017, 7:57 AMcoordinatorLayout {
drawerLayout {
relativeLayout {
MY MAIN CONTENT
}
navigationView {
inflateHeaderView(R.layout.header) <- UGLY HACK, I CANNOT GET IT TO WORK ANY OTHER WAY
}
}
appBarLayout(R.style.AppTheme_AppBarOverlay) {
toolbar()
}
}
but still it shows under the action bar (it's overlapped by it)miha-x64
04/24/2017, 8:35 AMdrawerLayout {
coordinatorLayout {
appBarLayout {
toolbar()
tabLayout()
}
frameLayout() /* content */
}
navigationView()
}
but DrawerLayout works with fitsSystemWindows incorrectly if it is specified not from AttributeSet, and AppBarLayout behaves poorly if created from code.
So I inflate a part of layout from XML.
But I can use NavigationView#addHeaderView
without any problems, and I also can create menu from code.anthaugh
04/24/2017, 9:07 AMval navHeader = relativeLayout {
imageView(R.drawable.menu_tile)
}
navigationView {
addHeaderView(navHeader)
...
}
I get The specified child already has a parent. You must call removeView() on the child's parent first.
Could you please elaborate on "DrawerLayout works with fitsSystemWindows incorrectly if it is specified not from AttributeSet, and AppBarLayout behaves poorly if created from code."? I can't see anything suspicious now.miha-x64
04/24/2017, 9:26 AMaddHeaderView(UI{ /* create a new Anko context */
relativeLayout { ... } /* root view is not attached, so you can use it */
}.view)
anthaugh
04/24/2017, 10:25 AMUI
but I can't reach it; AnkoContext.create()
is not a candidate here. I mingled with imports as well (import org.jetbrains.anko.UI
, import org.jetbrains.anko.UI as UIHelper
) to no avail.
On the other hand, using with(ui)
causes the same exception (regardless whether I use }.view()
or not). Not using with(ui)
at all makes no difference.miha-x64
04/24/2017, 10:26 AMbut I can’t reach itwhat do you mean?
anthaugh
04/24/2017, 10:30 AMimport org.jetbrains.anko.*
already) nor does it interpret UI as anko's UI. I am in a class inheriting from AnkoComponent, if that matters (that's why I tried to use with(ui)
)miha-x64
04/24/2017, 10:32 AMinline fun Context.UI(init: AnkoContext<Context>.() -> Unit): AnkoContext<Context>
in AnkoContext.kt, using Anko 0.10.0-beta-2
.anthaugh
04/24/2017, 10:41 AMaddHeaderView(context.UI { relativeLayout {
...
}}.view())
compiles, but throws IllegalStateException: View is already set: org.jetbrains.anko._RelativeLayout
. What do I do wrong? 😶anthaugh
04/24/2017, 10:41 AMUI(setContentBoolean = false)
makes no difference, btw)miha-x64
04/24/2017, 10:43 AMaddHeaderView(_RelativeLayout(context).apply {
// DSL here
})
miha-x64
04/24/2017, 10:51 AMaddHeaderView(
object : _RelativeLayout(context) { // sad crutch, fixes bottomPadding when keyboard is open
@TargetApi(20) override fun onApplyWindowInsets(insets: WindowInsets) = insets.consumeSystemWindowInsets()
}.apply { /* header view */
anthaugh
04/24/2017, 10:57 AMmiha-x64
04/24/2017, 10:59 AManthaugh
04/24/2017, 11:09 AManthaugh
04/24/2017, 11:13 AMmiha-x64
04/24/2017, 11:27 AM