-
创建button对象:
Button button1 =(Button)findViewById(R.id.button_1);
-
短通知提醒Toask
//Toast.makeText(Context对象,"提示文本内容",显示时长)
Toast.makeText(FirstActivity.this,"你点击button1",Toast.LENGTH_SHORT).show();
内置显示时长常量:Toast.LENGTH_SHORT、Toast.LENGTH_LONG
实例代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_layout);
Button button1 =(Button)findViewById(R.id.button_1);
button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Toast.makeText(FirstActivity.this,"你点击button1",Toast.LENGTH_SHORT).show();
}
});
}
运行效果: