http://www.codeproject.com/Articles/377432/Writing-an-Android-GUI-using-Python
1.[代码]按钮
MyButtonIndex = 1;
//#set onClick event listener
def MyButton_onClick(self,Ev) :
global MyButtonIndex;
//#Create a new button in scroll view
b = 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 object
MyButton.onClick = MyButton_onClick;
2.[代码]ScrollView
MyScrollLayout = Service.LinearLayoutClass._New(MyScroll);
MyScrollLayout.setOrientation("VERTICAL");
MyScrollLayout.setFrameLayoutParams(Service.FILL_PARENT,Service.WRAP_CONTENT);
3.[代码]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;
4.[代码]onPrepareOptionsMenu
def StarActivity_onPrepareOptionsMenu(self,menu) :
return True;
StarActivity.onPrepareOptionsMenu = StarActivity_onPrepareOptionsMenu;
5.[代码]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;
6.[代码]点击按钮打开对话框
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
7.[代码]创建对话框
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;
8.[图片] 屏幕截图
9.[文件] pythongui_menu_scrollview_popupwindow.rar ~ 791KB 下载(191)