I want to develop a chatting application for android. It will receive messages from the controller on the site. For this i have started designing a GUI. After practicing and
Label
widget so that you can control the text alignment i.e. left for text sent, and right for text received.:
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
halign: 'left'
valign: 'middle'
Label:
with RecycleView:CustomLabel
as the viewclass
data
RecycleView:
id: rv
viewclass: 'CustomLabel'
RecycleBoxLayout:
default_size_hint: 1, None
orientation: 'vertical'
The view is generatad by processing the data, essentially a list of dicts, and uses these dicts to generate instances of the viewclass as required.
data
The data used by the current view adapter. This is a list of dicts whose keys map to the corresponding property names of the viewclass.
data is an AliasProperty that gets and sets the data used to generate the views.
def display_txt(self):
self.ids.rv.data.append({'text': self.ids.txt.text, 'halign': 'left'})
self.ids.txt.text = ''
from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.lang import Builder
class SMS(Screen):
def send_txt(self):
self.ids.rv.data.append({'text': self.ids.txt.text, 'halign': 'left'})
self.ids.txt.text = ''
def receive_txt(self):
self.ids.rv.data.append({'text': self.ids.txt.text, 'halign': 'right'})
self.ids.txt.text = ''
Builder.load_file("main.kv")
class MyApp(App):
def build(self):
return SMS()
if __name__ == "__main__":
MyApp().run()
:
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
halign: 'left'
valign: 'middle'
:
GridLayout:
cols : 1
BoxLayout:
size_hint: 1, 0.1
Button:
text : 'Send'
on_press : root.send_txt()
Button:
text : 'Receive'
on_press : root.receive_txt()
TextInput:
hint_text : 'Write here'
id : txt
size_hint : .8 , .1
pos : 0 ,0
RecycleView:
id: rv
viewclass: 'ChatBox'
RecycleBoxLayout:
default_size_hint: 1, None
orientation: 'vertical'