solution is based on these things:
what does it do:
when first time toolbar is executing #setTitle, it creates AppCompatTextView and uses it to display title text.
when the AppCompatTextView is created, toolbar (as ViewGroup), adds it into it's own hierarchy with #addView method.
also, while trying to find solution i noticed that the textview has layout width set to "wrap_content", so i decided to make it "match_parent" and assign textalignment to "center".
MyToolbar.kt, skipping unrelated stuff (constructors/imports):
class MyToolbar : Toolbar {
override fun addView(child: View, params: ViewGroup.LayoutParams) {
if (child is TextView) {
params.width = ViewGroup.LayoutParams.MATCH_PARENT
child.textAlignment= View.TEXT_ALIGNMENT_CENTER
}
super.addView(child, params)
}
}
possible "side effects" - this will apply to "subtitle" too