Toast一般使用Toast.makeText(Context , String ,int ) 创建然后使用,show()方法显示在屏幕中。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ly = new LinearLayout(this) ;
Button btn = new Button(this) ;
btn.setText("弹出Toast") ;
ly.addView(btn) ;
setContentView(ly);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Toast", Toast.LENGTH_LONG).show() ;
}
}) ;
}