這個問題其實跟Kivy中其他控件支持中文一樣,都是字體的問題,而不是字符集的問題,但我看網上能搜到的答案,全都圍着字符集打轉,有些還煞有介事地回答説:給 FileChooserListView 增加 file_encodings: ["utf-8"] 屬性就能解決
其實根本沒用——人家官方文檔已經寫了,缺省的字符集就是:[‘utf-8’, ‘latin1’, ‘cp1252’],已經包含utf-8支持。
實際上只要增加font_name設置就可以了,比如官網示例,可以改成如下的模式:
<LoadDialog>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
# 這裏設置字體為安卓標準中文
font_name:'DroidSansFallback'
# -------------------------
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Load"
on_release: root.load(filechooser.path, filechooser.selection)
別忘了把字體文件放在項目哦。