I read that the greatest advantage of using Anko is its reuse. But I could not find his exact example.
Currently, in the new Android layout system, the boiler stove is as follows:
DrawerLayout (with some setup) CoordinatorLayout (with some setup) AppBarLayout (with some setup) ToolBar <The Main Content> NavigationView (with header inflated)
From the layout structure above, only <The Main Content> is varry. And also in many cases, this ceremonial setting is duplicated in almost every action.
So here, when Anko thinks, is there a reusable solution to this problem. I do not expect it to be reused for general purposes, but at least I can minimize the ceremonial code in the project. Maybe I need something like:
class MainUI: AnkoComponent<MainActivity> { override fun createView(ui: AnkoContext<MainActivity>): View{ return with(ui) { myCustomRootLayout { //here is what <The Main Content> will be } } } }
From the above code, im expecting myCustomRootLayout will do all the ceremonial setup for a root layout such as (DrawerLayout, CoordinatorLayout, etc. etc.).
Is it possible?
EDIT Therefore, I think my question is: How to create a custom component that can host another component
android android-layout kotlin anko
ktutnik
source share