public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
openButton = (Button) findViewById(R.id.open);
closeButton = (Button) findViewById(R.id.close);
openButtonOne = (Button) findViewById(R.id.openOne);
openButton.setOnClickListener(this);
closeButton.setOnClickListener(this);
openButtonOne.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.open:
msg ="开启Toast";
break;
case R.id.close:
msg ="关闭Toast";
break;
case R.id.openOne:
msg="打开服务";
break;
default:
break;
}
if (mToast != null) {
mToast.setText(msg);
mToast.setDuration(Toast.LENGTH_SHORT);
} else {
mToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
}
mToast.show();
}
本文提供了一个简单的 Android 应用示例,展示了如何使用 Toast 显示简短的消息提示。通过按钮点击事件触发不同类型的 Toast,包括开启、关闭及服务启动提示。
508

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



