This is not possible at the moment:
collapsingToolbarLayout {
id = TOOLBAR_LAYOUT_ID
fitsSystemWindows = true
contentScrim = ColorDrawable(colorAttr(R.attr.colorPrimary))
toolbar(ThemeOverlay_AppCompat_Dark_ActionBar) {
id = TOOLBAR_ID
popupTheme = ThemeOverlay_AppCompat_Light
}.lparams(width = matchParent, height = dimenAttr(R.attr.actionBarSize)){
collapseMode = COLLAPSE_MODE_PIN
}
}
This is the missing extension method:
fun <T : android.view.View> T.lparams(
width: kotlin.Int = wrapContent, height: kotlin.Int = wrapContent,
init: android.support.design.widget.CollapsingToolbarLayout.LayoutParams.() -> kotlin.Unit = defaultInit): T {
val layoutParams = android.support.design.widget.CollapsingToolbarLayout.LayoutParams(width, height)
layoutParams.init()
[email protected] = layoutParams
return this
}
I ran into the same issue. I'm able to use @fboldog's workaround, but digging deeper it looks like all the children of CollapsingToolBar are using FrameLayout.LayoutParams instead of CollapsingToolBar.LayoutParams: e.g. LayoutsTest.kt#L84
This would explain why children can't access CollapsingToolbarLayout's DSL. Trying to call any of these lparams also throws a nasty ClassCastException.
open class _CollapsingToolbarLayout(ctx: Context): android.support.design.widget.CollapsingToolbarLayout(ctx) {
fun <T: View> T.lparams(
c: android.content.Context?,
attrs: android.util.AttributeSet?,
init: android.widget.FrameLayout.LayoutParams.() -> Unit = defaultInit
): T {
val layoutParams = android.widget.FrameLayout.LayoutParams(c!!, attrs!!)
layoutParams.init()
[email protected] = layoutParams
return this
}
// ... and the others ...
It looks like all we need to do is just change the functions to use CollapsibleToolbarLayout.LayoutParams. I'll open a PR tonight if this is the proper approach.
Has anything happened here yet? I will look into it tomorrow.
@yanex I was unable to build the project. I tried AS and IDEA but without success. Neither dev or master. Also followed doc/building.md but without luck.
I think I have pinpointed the problem. In https://github.com/Kotlin/anko/blob/master/anko/library/generator/src/org/jetbrains/android/anko/generator/layoutParamsUtils.kt, you use the generateLayoutParams method to determine the LayoutParams from the return type but you should use generateDefaultLayoutParams since that one always return the correct LayoutParams.
For collapsing CollapsingToolbarLayout generateLayoutParams it returns FrameLayout.LayoutParams and thus does not accept any configuration for CollapsingToolbarLayout.
On a side note, if you could help me to build I'd be happy to fix this. And do some more contributing for 9.1 release.
Has there been any work done to fix this issue yet?
@nomisRev I don't know if this was the build issue you were seeing back in October, but I just tried to build the project locally and encountered an error during the ant -f update_dependencies.xml step, since apparently the ant-contrib library is no longer present at http://heanet.dl.sourceforge.net/project/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip (the route in the update_dependencies.xml file). I plan on putting up a pull request which fixes this issue soon.
This issue has been up for a year and a half now... Is Anko dead?
I broke my head. This material design with flying and disappearing widgets is weird itself but Anko could add more headache
Haven't tried it yet, but thanks for fixing this!
Most helpful comment
This issue has been up for a year and a half now... Is Anko dead?