Android QPython3 可視化-三鍵按鈕:ButtonText.py
#需要BaseWindow.py??https://www.bilibili.com/read/cv8680125
from BaseWindow import *
BT="""
? ? <Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="%s"
android:id="@+id/but_yes"
android:textSize="8dp"
android:background="#3f3f7f"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
""","""
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="%s"
android:id="@+id/but_can"
android:textSize="8dp"
android:background="#7f3f3f"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
""","""
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="%s"
android:id="@+id/but_noo"
android:textSize="8dp"
android:background="#7f7f00"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
"""
XML="""<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#007f7f"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="20">
<ScrollView? ?
? ? ? ? android:layout_width="fill_parent"? ?
? ? ? ? android:layout_height="fill_parent" >?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="20">
? ? <EditText
android:id="@+id/editTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="8dp"
android:text=""
android:textColor="#0000ff"
android:layout_weight="1"
android:gravity="center"
/>
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="8dp"
android:text=""
android:textColor="#ff0000"
android:layout_weight="1"
/>
</LinearLayout>
</ScrollView>
? ? </LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:layout_weight="8">
""","""
</LinearLayout>
</LinearLayout>"""
class MainScreen(Layout):
? ? def on_show(self):
? ? ? ? #if self.Count>=0:
? ? ? ? self.views.but_yes.add_event(click_EventHandler(self.views.but_yes,self.yes))
? ? ? ? if self.Count>1:
? ? ? ? ? ? self.views.but_noo.add_event(click_EventHandler(self.views.but_noo,self.noo))
? ? ? ? if self.Count>2:
? ? ? ? ? ? self.views.but_can.add_event(click_EventHandler(self.views.but_can,self.can))
? ? ? ? self.views.editTitle.text=self.Title
? ? ? ? self.views.editText.text=self.Text
? ? def on_close(self):
? ? ? ? pass
? ? def yes(self,view,dummy):
? ? ? ? MainScreen.Text=1
? ? ? ? FullScreenWrapper2App.close_layout()
? ? def noo(self,view,dummy):
? ? ? ? MainScreen.Text=-1
? ? ? ? FullScreenWrapper2App.close_layout()
? ? def can(self,view,dummy):
? ? ? ? MainScreen.Text=0
? ? ? ? FullScreenWrapper2App.close_layout()
YNC=('是','否','取消')
def ButtonText(Title='',Text='',button=YNC):#主函數(shù)
#三按鈕對(duì)話框(標(biāo)題,內(nèi)容,("是"按鈕文本,"否"按鈕文本,"取消"按鈕文本))
#返回:是=1,否=-1,取消=0
#省按鈕(button)格式:默認(rèn)為("是","否","取消")
#三按鈕(button)格式:("是"按鈕文本,"否"按鈕文本,"取消"按鈕文本)
#二按鈕(button)格式:("是"按鈕文本,"否"按鈕文本)
#單按鈕(button)格式:("是"按鈕文本,)
#空按鈕(button)格式:(),等價(jià)于單按鈕("OK",)
? ? MainScreen.Title=Title
? ? MainScreen.Text=Text
? ? b=[XML[0]]
? ? MainScreen.Count=l=len(button)
? ? if l==3:
? ? ? ? a=(button[0],button[2],button[1])
? ? elif l==2:
? ? ? ? a=(button[0],'',button[1])
? ? elif l==1:
? ? ? ? a=(button[0],'','')
? ? else:#l==0
? ? ? ? a=('OK','','')
? ? for i in range(3):
? ? ? ? if a[i]:
? ? ? ? ? ? b.append(BT[i]%a[i])
? ? b.append(XML[1])
? ? b=''.join(b)
? ? FullScreenWrapper2App.show_layout(MainScreen(b,'Button'))
? ? FullScreenWrapper2App.eventloop()
? ? b=MainScreen.Text
? ? del MainScreen.Title,MainScreen.Text,MainScreen.Count
? ? return b
__all__=('ButtonText','droid')
==========說明==========

返回:是=1,否=-1,取消=0
Android 5.0 系統(tǒng)以上,遇到Button英文全部自動(dòng)變?yōu)榇髮懡鉀Q方案:
Button繼承至TextView,把Button改成TextView打回原形就可以了。
例如:
<Button
#其他內(nèi)容#? />
改為:
<TextView
android:clickable="true"
#其他內(nèi)容#? />
作者:乘著船@Bilibili
更多文章+下載鏈接:https://www.bilibili.com/read/readlist/rl321663