I have been trying to set toolbar like this:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ui()
}
}
fun MainActivity.ui() = frameLayout {
toolbar {
title = "Mist Player"
}.let { setSupportActionBar(it) }
mainView { recyclerList().let { bindList(it) } }
}
but can't get it to work. How to get around this ?
I think the easiest way is to assign an id to your toolbar, and set the action bar in onCreate(), like this:
In res/values/ids.xml
<resources>
<item name="toolbar" type="id"/>
</resources>
In your MainActivity class:
onCreate(...) {
super.onCreate(...)
setSupportActionBar(findOptional<Toolbar>(R.id.toolbar))
}
toolbar {
title = "Mist Player"
id = R.id.toolbar
}
@gregschlom findOptional gives an error? how to use it ? and what it does ?
how to change baground for activity and how to use id in anko
@mridah
@lupajz
@gregschlom
Most helpful comment
I think the easiest way is to assign an id to your toolbar, and set the action bar in onCreate(), like this:
In res/values/ids.xml
In your MainActivity class: