我有一个包含自定义按钮的ListView。如何调整滚动条的格式,使其始终可见(如果有需要滚动的内容...),将其扩宽(10个点而不是默认的2个点)并给它不同的颜色?
DoScroll.py文件:
DoScroll.py文件:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.listview import ListItemButton
class ShowItems(BoxLayout):
def get_list(self):
self.results.item_strings = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
def show_capital(self, capital):
print capital
class CapitalButton(ListItemButton):
pass
class DoScrollApp(App):
pass
if __name__ == '__main__':
DoScrollApp().run()
这里是DoScroll.kv文件。
#: import DoScroll DoScroll
#: import ListAdapter kivy.adapters.listadapter.ListAdapter
<CapitalButton>:
text_size: self.width - 50, None
halign: 'left'
valign: 'middle'
font_size: 16
on_press: app.root.show_capital(self.text)
ShowItems:
<ShowItems>:
results: results_list
orientation: "vertical"
BoxLayout:
height: "40dp"
size_hint_y: None
Button:
text: "Get the list"
on_press: root.get_list()
ListView:
id: results_list
adapter:
ListAdapter(data=[], args_converter=lambda row_index,
an_obj: {'text': an_obj,'size_hint_y': None,'height': 40}, cls=DoScroll.CapitalButton)