Android――常用代码段积累(一)

来源:互联网 时间:1970-01-01

 

 

1,Toast

 

 // 登录成功之后跳转到home Toast.makeText(getApplicationContext(), 登陆成功!, Toast.LENGTH_SHORT).show();

 

2,简单提示框

 

 AlertDialog.Builder builder = new Builder(home.this); builder.setMessage(确定要退出吗?); builder.setTitle(提示); builder.setPositiveButton(确认, new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); home.this.finish(); //关闭掉Activity } }); builder.setNegativeButton(取消, new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); 

 

3,处理返回按钮

 

 

/*处理返回按钮的问题*/ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { dialog(); return false; } return false; }

 

 

 

 

 

 



相关阅读:
Top