The straight forward way to do it: Add a right action item the same size as your left action time. This will cause the area for the Label to be centered.
A little more complicated. I used the same concept but force the size of the area used for the right action items to match the size of the left action times. You can see the kv code for the MDToolbar here: https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/toolbar/toolbar.kv
I used the id’s in the toolbar to dynamically make the modifications. I added a label to your example to make it easy to see the true center.
from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.uix.toolbar import MDToolbar
from kivy.properties import BooleanProperty
kv = """
MDBoxLayout:
orientation: "vertical"
Label
size_hint_y: None
height: 24
color: 'black'
text: 'Center'
CenteredMDToolbar:
title: "MyTitle"
anchor_title: 'center'
md_bg_color: .5,.5,.5,.1
specific_text_color: 1,1,1,.9
left_action_items: [["chevron-left", lambda x: x]]
# right_action_items: [["chevron-left", lambda x: x]]
"""
class CenteredMDToolbar(MDToolbar):
def on_kv_post(self, base_widget):
self.ids.left_actions.bind(size=self.re_center)
def re_center(self, obj, v):
self.ids.right_actions.width = self.ids.left_actions.width
class CenterTaskBarApp(MDApp):
def build(self):
return Builder.load_string(kv)
CenterTaskBarApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f3f1e221-c509-400a-ae57-0a2aede0b609n%40googlegroups.com.