Kivy Android 项目开发全解析
1. 从 Python 显示 Toast 消息
在开发 Android 应用时,有时需要显示一些简短的提示信息,Toast 消息就是一个很好的选择。在 Python 中,我们可以借助 PythonActivity 类中的 toastError() 方法来实现这一功能。
1.1 toastError() 方法实现
以下是 toastError() 方法的具体实现代码:
public void toastError(final String msg) {
final Activity thisActivity = this;
runOnUiThread(new Runnable () {
public void run() {
Toast.makeText(thisActivity, msg, Toast.LENGTH_LONG).show();
}
});
// Wait to show the error.
synchronized (this) {
try {
this.wait(1000);
} catch (InterruptedException e) {
}
}
}
这个方法接收一个字符串参数 msg </
超级会员免费看
订阅专栏 解锁全文

1090

被折叠的 条评论
为什么被折叠?



