android在Service,BroadCast onReceiver()中弹出Dialog对话框
生活随笔
收集整理的這篇文章主要介紹了
android在Service,BroadCast onReceiver()中弹出Dialog对话框
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
寫好Alter功能塊后,在alter.show()語句前加入:
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);注:alter為AlertDialog類型對象
然后在AndroidManifest.xml中加入權限:
<uses-permission?android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission>下面進行簡單的解釋:
如果只在Service中寫入常在Activity中使用的創(chuàng)建Alter的代碼,運行時是會發(fā)生錯誤的,因為Alter的顯示需要依附于一個確定的Activity類。而以上做法就是聲明我們要彈出的這個提示框是一個系統(tǒng)的提示框,即全局性質的提示框,所以只要手機處于開機狀態(tài),無論它現(xiàn)在處于何種界面之下,只要調用alter.show(),就會彈出提示框來。
demo如下:
AlertDialog.Builder?builder?=?new?AlertDialog.Builder(this);? builder.setMessage("Are?you?sure?you?want?to?exit?")?.setCancelable(false)?.setPositiveButton("Yes",?new?DialogInterface.OnClickListener()?{?public?void?onClick(DialogInterface?dialog,?int?id)?{?MyActivity.this.finish();?}?})?.setNegativeButton("No",?new?DialogInterface.OnClickListener()?{?public?void?onClick(DialogInterface?dialog,?int?id)?{?dialog.cancel();?}?});?AlertDialog?alert?=?builder.create();?alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);alert.show();?
?
?
Android UI學習 - 對話框 (AlertDialog & ProgressDialog)
http://android.blog.51cto.com/268543/333769
轉載于:https://my.oschina.net/thc/blog/493325
總結
以上是生活随笔為你收集整理的android在Service,BroadCast onReceiver()中弹出Dialog对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python binary lib on
- 下一篇: 在项目中引入领域驱动设计的经验