« android通过xml配置实现的动画效果milestone的基本信息 » android...
生活随笔
收集整理的這篇文章主要介紹了
« android通过xml配置实现的动画效果milestone的基本信息 » android...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
用戶在點擊手機的返回按鈕時,默認是推出當前的activty,但是有時用戶不小心按到返回,所以需要給用戶一個提示,這就需要重寫onkeydown事件,實現的效果如下:
實現代碼如下:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } protected void dialog() { AlertDialog.Builder builder = new Builder(HanderTestActivty.this); builder.setMessage("確定要退出嗎?"); builder.setTitle("提示"); builder.setPositiveButton("確認", new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); HanderTestActivty.this.finish(); } }); builder.setNegativeButton("取消", new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { dialog(); return false; } return false; } http://wangjun.easymorse.com/
轉載于:https://my.oschina.net/xiahuawuyu/blog/82936
總結
以上是生活随笔為你收集整理的« android通过xml配置实现的动画效果milestone的基本信息 » android...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js对表格自动排序
- 下一篇: IIS7下 301重定向 添加WWW