使用 Python 编写 Android 的 UI 应用,pythonandroid,http://www.c
分享于 点击 37843 次 点评:107
使用 Python 编写 Android 的 UI 应用,pythonandroid,http://www.c
http://www.codeproject.com/Articles/377432/Writing-an-Android-GUI-using-Python
按钮
MyButtonIndex = 1;//#set onClick event listenerdef MyButton_onClick(self,Ev) :global MyButtonIndex;//#Create a new button in scroll viewb = Service.ButtonClass._New(MyScrollLayout);//#Set text content and color b.setText("Button" + str(MyButtonIndex)); b.setTextColor(0xFFFF0000); b.setLinearLayoutParams(Service.FILL_PARENT,Service.WRAP_CONTENT); MyButtonIndex = MyButtonIndex + 1;return;//#assign event listener to objectMyButton.onClick = MyButton_onClick;
ScrollView
MyScrollLayout = Service.LinearLayoutClass._New(MyScroll);MyScrollLayout.setOrientation("VERTICAL");MyScrollLayout.setFrameLayoutParams(Service.FILL_PARENT,Service.WRAP_CONTENT);
onCreateOptionsMenu
def StarActivity_onCreateOptionsMenu(self,menu) : menu.add1(0, 1, 1, "open"); menu.add1(0, 2, 2, "edit"); menu.add1(0, 3, 3, "update"); menu.add1(0, 4, 4, "clode"); return True;StarActivity.onCreateOptionsMenu = StarActivity_onCreateOptionsMenu;
onPrepareOptionsMenu
def StarActivity_onPrepareOptionsMenu(self,menu) : return True;StarActivity.onPrepareOptionsMenu = StarActivity_onPrepareOptionsMenu;
onOptionsItemSelected
def StarActivity_onOptionsItemSelected(self,menuitem) : id = menuitem.getItemId(); if( id == 1 ) : self.setTitle("Open Text!"); if( id == 2 ) : self.setTitle("Edit Text!"); if( id == 3 ) : self.setTitle("Update Text!"); if( id == 4 ) : self.setTitle("Close Text!"); return True; StarActivity.onOptionsItemSelected = StarActivity_onOptionsItemSelected;
点击按钮打开对话框
OpenPopWindowButton = Service.ButtonClass._New(ButtonLayout);OpenPopWindowButton.setText("Open popup window");OpenPopWindowButton.setLinearLayoutParams(Service.WRAP_CONTENT,Service.WRAP_CONTENT); def OpenPopWindowButton_onClick(self, Ev): … return;OpenPopWindowButton.onClick = OpenPopWindowButton_onClick
创建对话框
def OpenPopWindowButton_onClick(self, Ev): //#create popup window MyPopupWindow = Service.PopupWindowClass._New() //#set onDismiss event listener def MyPopupWindow_onDismiss(self, Ev): Service.ToastClass._New().makeText("PopupWindow is dismiss",0).show(); return; MyPopupWindow.onDismiss = MyPopupWindow_onDismiss; //#create root layout for popup window PopupLayout = Service.LinearLayoutClass._New(); PopupLayout.setBackgroundColor(0xFF0000FF) #--blue //#create a button MyButton = Service.ButtonClass._New(PopupLayout); def MyButton_onClick(self, Ev) : //#when is clicked, we show information and close the popup window Service.ToastClass._New().makeText("Button is click",0).show(); MyPopupWindow.dismiss(); return; MyButton.onClick = MyButton_onClick; MyButton.setText("CloseWindow"); MyButton.setLinearLayoutParams(Service.WRAP_CONTENT,Service.WRAP_CONTENT); //#assign layout to popup window. MyPopupWindow.setContentView(PopupLayout); MyPopupWindow.setWidth(200); MyPopupWindow.setHeight(200); MyPopupWindow.setFocusable(True); MyPopupWindow.showAtLocation(self,17,0,0); //#prevent garbage collected by python. MyPopupWindow._LockGC(); return;
屏幕截图
imgs/asCode/04073413_0S87.jpg
用户点评