有办法更改Kivy中的TextInput hint_text字体大小吗?我找不到任何关于使用hint_text_size
的文档。
TextInput:
id: text_input_unique
hint_text: 'example: Stand25'
hint_text_size: 16
multiline: False
size_hint_y: None
height: 50
font_size: 32
halign: 'center'
cursor_color: (0,0,0,1)
TextInput
对hint_text
使用与对主文本相同的字体属性(颜色除外(。这里是TextInput
的一个扩展,它尊重hint_font_size
的属性:
class TextInputwHintSize(TextInput):
hint_font_size = NumericProperty(sp(15))
def __init__(self, **kwargs):
self.regular_font_size = sp(15)
self.ignore_font_size_change = False
super(TextInputwHintSize, self).__init__(**kwargs)
Clock.schedule_once(self.set_font_size)
def set_font_size(self, dt):
self.ignore_font_size_change = True
if self.text == '':
self.font_size = self.hint_font_size
def on_font_size(self, instance, size):
if self.ignore_font_size_change:
return
self.regular_font_size = size
def on_text(self, instance, text):
if text == '':
self.font_size = self.hint_font_size
else:
self.font_size = self.regular_font_size
例如,使用这样的方法:
TextInputwHintSize:
id: text_input_unique
hint_text: 'example: Stand25'
hint_font_size: 16
multiline: False
size_hint_y: None
height: 50
font_size: 32
halign: 'center'
cursor_color: (0,0,0,1)