How can I change the height of a textfield in KivyMD 2?

In the code block below, I made a text field which already has adaptive width with size_hint_x: 0.86. I want my text field to be able to have the right size no matter which device it is displayed on, but textfield doesn’t seem to have a size_hint_y attribute, so on smaller displays the text field looks way too large. I also tried setting the height manually with height: 50, but that didn’t work either. I don’t want to set the maximum height, I want to set the exact height of the text field.

from kivymd.app import MDApp
from kivy.core.window import Window
from kivy.lang import Builder

searchHelper = """
MDScreen:
    md_bg_color: app.theme_cls.backgroundColor

    MDTextField:
        mode: "outlined"
        hint_text: "Search..."
        pos_hint: {"center_x": 0.5, "center_y": 0.93}
        size_hint_x: 0.86

        MDTextFieldHintText:
            text: "Search"

"""
Window.size = (220*2, 430*2)

class MainApp(MDApp):
    def build(self):
        self.theme_cls.primary_palette = "White"
        return Builder.load_string(searchHelper)
    
MainApp().run()

Leave a Comment